Date problem

1. Senior Member
Join Date
Dec 1969
Posts
119

## Date problem

I am trying to store the day of the month and the month in separate variables. But even in mm/dd/yy format, if I write 13/10/99 (Some arbitrary month, 10th day and 99 year), the database always converts it into 10/13/99, which does not serve my purpose. Any solutions?<BR>Thanks

2. John Weeflaar Guest

## RE: Date problem

You can use Month(), Day(), and Year() functions to extract<BR>the month, day and year.<BR>eg:<BR>strDate = "5/9/99"<BR>strMonth = Month(strDate) &#039 returns 5<BR>strDay = Day(strDate) &#039returns 9<BR>strYear = Year(strYear) &#039returns 99<BR><BR>I guess the database understands that if we write:<BR>13/10/99<BR>because the max for month is 12, then we may mean<BR>10/13/99<BR>But if you type 4/9/99 , it wouldn&#039t convert it into 9/4/99.<BR><BR>John

3. John Weeflaar Guest

## RE: Date problem

should be:<BR><BR>strYear = Year(strDate) &#039returns 99<BR>

4. Senior Member
Join Date
Dec 1969
Posts
119

## RE: Date problem

Thanks John, but that&#039s precisely what&#039s my problem. In no case I want the conversion, whether that is 13/10/99 or 12/10/99(Dec 12, 1999). I am trying to write a program which will validate the date and this requires that no such conversion should take place, else all my variables will go haywire.<BR>Any idea?

5. John Weeflaar Guest

## RE: Date problem

Hi Arvind,<BR><BR>Here, I created a function to make sure that<BR>the date such as: 13/10/99 (13 &#062; 12, false)<BR> -2/10/99 (-2 &#060;= 0, false)<BR> 5/34/99 (34 &#062; 31, false)<BR> 5/-2/99 (-2 &#060;= 0, false)<BR>will return a false.<BR>If the function returns false, you can then alert the user<BR>to reenter the correct date etc.<BR><BR>Function IsCorrectDate(theDate)<BR> searchStr = "/"<BR> foundpos = InStr(theDate,searchStr) <BR> &#039 get the first position of "/"<BR> grabfirstStr = Left(theDate, foundpos - 1) <BR> &#039 get the substring up to just before /<BR> foundposnext = InStr(foundpos+ 1,theDate, searchStr)<BR> &#039 get the next position of /<BR> midlen = foundposnext - (foundpos + 1) <BR> &#039 get the length from just after the first / to the second /<BR> grabnextStr = Mid(theDate,foundpos + 1, midlen)<BR> &#039 get the next substring from just after first / to just <BR> &#039 before second /<BR> &#039 Use these Response.Write() to see the 2 strings extracted<BR> &#039 Response.Write("first String is: " & grabfirstStr)<BR> &#039 Response.Write("second String is: " & grabnextStr)<BR> If (CInt(grabfirstStr) &#062; 12) OR (CInt(grabfirstStr) &#060;= 0) _<BR> OR( CInt(grabnextStr) &#062; 31 ) OR (CInt(grabnextStr) &#060;= 0) Then<BR> IsCorrectDate = False<BR> Else<BR> IsCorrectDate = True<BR> End If<BR>End Function<BR><BR>You can then call this function for example:<BR>theDate = "2/35/99"<BR> If Not IsCorrectDate(theDate) Then &#039 if returns false<BR> Response.Write("Incorrect Date")<BR> Else<BR> &#039 the date is correct so go to next processing<BR> End If<BR><BR>You may want to modify the function for your needs.<BR>This is just an example.<BR><BR>Happy Programming!<BR><BR>John

#### Posting Permissions

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