Date problem

# Thread: Date problem

1. Senior Member
Join Date
Dec 1969
Posts
517

## Date problem

I have the following code: <BR>...<BR>ed = date <BR>If py = "3 months" then <BR> etd = DateAdd("d",+85,FormatDateTime(ed, vbShortDate)) <BR> elseif py = "6 months" then <BR> etd = DateAdd("d",+170,FormatDateTime(ed, vbShortDate)) <BR> elseif py = "12 months" then <BR> etd = DateAdd("d",+360,FormatDateTime(ed, vbShortDate)) <BR> end if <BR>Response.Write (etd) //-&#062; 1/1/1900<BR>Why am I getting "1/1/1900" when I choose 12 months??? <BR><BR>Thank you.

2. jd
Senior Member
Join Date
Dec 1969
Posts
850

## RE: Date problem

The DateAdd function expects a date as the third parameter, whereas you are passing it a string, making an extra type conversion necessary. You might try this:<BR><BR>===============================<BR>ed = date <BR>If py = "3 months" then <BR>&nbsp;&nbsp;&nbsp;Â*Â*Â*etd = DateAdd("d",85,ed) <BR>elseif py = "6 months" then <BR>&nbsp;&nbsp;&nbsp;Â*Â*Â*etd = DateAdd("d",170,ed) <BR>elseif py = "12 months" then <BR>&nbsp;&nbsp;&nbsp;Â*Â*Â*etd = DateAdd("d",360,ed) <BR>end if <BR>Response.Write FormatDateTime(etd, vbShortDate)<BR>===============================<BR ><BR>and see if that helps you. Also, I assume you have your own business-related reasons for choosing the 85, 170 and 360 values... but if you want actual calendar time, you could use this:<BR><BR><BR>===============================<B R>ed = date <BR>If py = "3 months" then <BR>&nbsp;&nbsp;&nbsp; etd = DateAdd("m",3,ed) <BR>elseif py = "6 months" then <BR>&nbsp;&nbsp;&nbsp; etd = DateAdd("m",6,ed) <BR>elseif py = "12 months" then <BR>&nbsp;&nbsp;&nbsp; etd = DateAdd("m",12,ed)<BR>end if <BR>Response.Write FormatDateTime(etd, vbShortDate)<BR>===============================<BR ><BR>

3. Senior Member
Join Date
Dec 1969
Posts
517

## Thank you

...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•