1

i am doing this work using classic asp on webmatrix

in my database the dates stored are in the format mm/dd/yyyy

when i write those on a webpage the dates change format and become dd/mm/yyyy

also the fact that different users might have their system date format in different ways. Is there is a way to bypass that and get and show date in a fixed format.

appreciate your help and time

Vin

Vinod
  • 130
  • 1
  • 12
  • 1
    the problem is not the system date format from users, the problem is the system date format in the server – Rafael May 11 '14 at 12:48
  • possible duplicate of [Classic ASP - Format current date and time](http://stackoverflow.com/questions/22574092/classic-asp-format-current-date-and-time) – user692942 May 11 '14 at 13:05
  • 1
    What @Rafael says is correct [tag:asp-classic] is a "server side" language this means that any date generated uses the "regional settings" of the server it was called from, so if your using a `US` server for example running `Date()` would give you `05/11/2014` whereas if you are using a `UK` server the same code will return `11/05/2014`. So any specific formatting contrary to the server regional settings has to be done in code using in-built date functions (see my link in [previous comment](http://stackoverflow.com/questions/23591793/implicit-date-format-conversion#comment36212315_23591793)). – user692942 May 11 '14 at 17:10
  • @Lankymart i won't consider this question as dupe, because while both uestion are about date format, the refered question is not the same iusse than this. this question has another answer – Rafael May 11 '14 at 17:15
  • @Rafael Write an answer then. – user692942 May 11 '14 at 17:36
  • 1
    First of all thank you Rafael and @Lankymart for your time and input. Here's what i did. I Set Session.LCID = 1033 (for US). All problems solved because while i was seeing the DB date format as mm/dd/yyyy, the screen was not. In case if my DB was using dd/mm/yyyy then i would have to use Session.LCID = 2057 (for UK). Thank you so much everyone. – Vinod May 12 '14 at 10:39

1 Answers1

2

You infered well, ASP more accurately The ASP engine in your web server (IIS) is converting imlpicitily all your date values, based on the system regional settings in your Server.

Doesn't matter in which format do you have stored the date values in the database, ASP will allways convert it all. Exists two altenatives to correct this:

the use of LCID property

The LCID property specifies how dates, times, and currencies are formatted. Locale identifiers (LCIDs) are not the same for each geographical locale. Some locales format dates as YY-MM-DD, and some format dates as MM-DD-YYYY. The LCID property is read/write.

The LCID is supported in Session and in Response (this only supported in recent versions of windows) Object.

depending where you live or where your clients are from you can choose the LCID more appropiated to them in this list of LCID Numbers

More Information:

MSDN - Response.LCID

MSDN - Session.LCID

change the regional settings in your server

check this thread for more information

ASP Classic & SQL date out-of-range error

(check the quick fix part)

Community
  • 1
  • 1
Rafael
  • 3,081
  • 6
  • 32
  • 53
  • thanks for the informative response. I am not using SQL Server. Its SQL CE that comes with WebMatrix. Part of the Quick fix is possible, but now am concerned about the data already in the DB and the formats for those. But this is good stuff you have posted in here. Many thanks. – Vinod May 12 '14 at 08:45
  • 1
    Thanks so much Rafael. i used Session.LCID = 1033 and everything worked fine. Appreciate your time and assistance. – Vinod May 12 '14 at 10:40