Click to See Complete Forum and Search --> : Dates? lol and not the type we all want!


Calmaris
02-19-2004, 08:38 AM
Ok a date is put into my database, what I want to do is add a month to that date and insert that new date somewhere as well. I've tried using Dateserial with the examples from 4guysfromrolla but I'm only getting errors this is the code I am using.

Dim SomeDate
SomeDate = DateSerial(1998, 3, 14)
SomeDate = DateSerial(Year(Date), Month(Date) - 1, 1 - 1)

Some date will be inserted as is into the database but I need the date 1998,4,14 to be inserted as well.

buntine
02-19-2004, 09:12 AM
Try the following code which uses ASP's dateAdd() method:


Dim someDate, newDate
someDate = dateValue("14-3-98")
newDate = dateAdd("m", 1, someDate)

response.write("Original date: " & CDate(someDate) & vbCrLf);
response.write("Altered date: " & CDate(newDate) & vbCrLf);


First we store a valid date in a variable and name it someDate. Then we use ASP's dateAdd() method to add one month to the original date.

Lastly, we write the two dates to the screen and use ASP's cast date method to ensure both variable are of subtype date.

Regards,
Andrew Buntine.