calculate date

  • Thread starter Thread starter Newbie
  • Start date Start date
N

Newbie

Hi,

I have a datepicker that gives a date - when I use the date entered I want
it to convert the dateto control value to the month end date of the month
selected (mdateto) and then mdatefrom is to be calculated using the mdateto,
mdatefrom = 12 months prior to the mdateto value

eg1
dateto control = '17/12/2003' ...... mdateto = 31/12/2003

mdatefrom = 1/1/2003

eg 2
dateto control = '4/4/2003' ....... mdateto = 30/4/2003

mdatefrom = 1/5/2002
 
Use DateSerial function:
Sub TestDates()
Dim mdateto As Date, mdatefrom As Date

mdateto = DateValue("17/12/2003")
mdateto = DateSerial(Year(mdateto), Month(mdateto) + 1, 1 -
1)

mdatefrom = DateSerial(Year(mdateto) - 1, Month(mdateto) +
1, 1)

MsgBox mdateto & vbCr & mdatefrom

End Sub
 
Thanks - I'll give it a go



losmac said:
Use DateSerial function:
Sub TestDates()
Dim mdateto As Date, mdatefrom As Date

mdateto = DateValue("17/12/2003")
mdateto = DateSerial(Year(mdateto), Month(mdateto) + 1, 1 -
1)

mdatefrom = DateSerial(Year(mdateto) - 1, Month(mdateto) +
1, 1)

MsgBox mdateto & vbCr & mdatefrom

End Sub
 
Back
Top