Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
An HTML Form has 2 textboxes where in users will have to enter dates in dd/mm/yyyy format in both the textboxes. Records which fall within these 2 dates will only be retrieved from the backend. Now what I have noticed is if the date in the 1st textbox is entered as 01/04/2001 (i.e. 1st April 2001), then the records starting from 1st April 2001 are retrieved which is correct but even if the date in the 1st textbox is entered as 04/01/2001 (i.e. 4th January 2001) then also the records starting from 1st April 2001 are retrieved. Why is this happening? How do I make ASP understand that 01/04/2001 means 1st April 2001 & 04/01/2001 means 4th January 2001? Please note that the date format given in the Regional Options (under Control Panel) in my PC is in dd/mm/yyyy format.

Thanks,

Arpan
 
Your problem doesn't come from asp but from your database. I've allready noticed that, for Ms databases like Access or SQL Server, I had to translate dates in american format (MM/DD/YYYY) to use them in SQL queries. So what I did is the following : create a ConvDateForSQL function that'll change month and day places in you date and replace all queries that look like
Code:
SELEC .. FROM .. WHERE mydate = '" & mydate & "';"
to
Code:
SELEC .. FROM .. WHERE mydate = '" & ConvDateForSQL(mydate) & "';"

Note : if you are using comma (",") as decimal separator and have money fields (or any other float value) in any query, you'll have to do the same to replace the coma by a point. Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top