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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates not working right, MM switching with DD

Status
Not open for further replies.

CzechNET

Programmer
Nov 2, 2004
28
0
0
CA
Hello,

I have a strange situation with a script I wrote. I have a script that uses dates extensively, user can select a date from 3 drop down menus (dd/mm/yyyy), save it to the database, then the entry is queried for specific date and then the entry is displayed. (In a nutshell :)

Now when I run the script on a server with UK locale the dates get assembled correctly, saved in the database correctly, when queried for a specific date it works correctly, but as soon as I fill a recordset the dates switch from dd/mm/yyyy to mm/dd/yyyy
and only if the day value is less then 10, so for example May 3rd would end up being displayed and read by ASP as March 5th, even though the database has the date corectly. Any ideas why it would happen and how I can fix it ? LCID is set to UK.
 
ASP default format date. I take the string apart and reformat it manually to what i need...

Bastien

Cat, the other other white meat
 
Where do you set the default format ? Taking it apart won't work because ASP already thinks the days are month and vise versa so I'd end up with the same date, plus it only screws up when days are less then 10, if days are say 22 (of March) the date will show up correctly.
 
I'm using both Access and MS-SQL for this app, though the dates ARE saved correctly, but as soon as I fill a recordset they get screwed. I don't really think that the SQL convert will help much, but I'll give it a try.
 
Maybe the CDate function will help. Perhaps if you saved it as a string in the database... instead of as a date field.

I am assuming that CDate() will create the same value for "January 2 2005" as it does for "2 January 2005" ... but I'm too lazy to test it.

 
OK, I lied... I'm not THAT lazy. I tested it and it seemed to work.

Code:
<%@ Language=VBScript %>
<%
Dim A, B
A = CDate("Jan 2 2005")
B = CDate("2 Jan 2005")
Response.Write "Result: " & cStr(cBool(A = B))
%>
 
That'd be going into a wrong direction, saving a date value in a string would limit you in a lot ways.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top