Link to home
Start Free TrialLog in
Avatar of DCPAus
DCPAus

asked on

Response.write Date - Format question

My server is set to English (Australian) the short format date is dd/MM/yyyy

the long Format is dddd, d MMMM,yyyy

Yet when I do a response.write Date it comes up as

mm/dd/yyyy

Why ?

Id there anyway that I can force the .write Date function to be dd/MM/yyyy or preferably dddd, d MMMM,yyyy.

I have also tried the following
sTestDate=formatdatetime(Date,2)
response.write sTestDate

with no luck

Help would be appreciated
Avatar of gladxml
gladxml

DCPAus,

I think you hit the refresh...

This is a duplicate question..

Check the link below for the original question..

https://www.experts-exchange.com/questions/20524705/Response-write-Date-Format-question.html

>>>DO NOT ACCEPT THIS AS AN ANSWER<<<<<


Regards,
gladxml
sTestDate=formatdatetime(Date,1)
Have you set the locale ID to the correct value?

Do not assume that your IIS server is correctly set by default.

At the beginning of your ASP script (or in an INCLUDE file) it is good practice to set the locale ID to your preferred value. (2057 for UK, 1033 for USA, 1031 for Germany).
e.g.
<%
session.LCID ="2057"
%>

This is important when handling US/UK/AU date formats as "1/12/2003" is 1 December in UK/AU and January 12 in USA formats).  You can also switch LCID several times on the same page if you wish or make it dynamicly responsive to what you think is best for the page visitor.  Note that LCID affects not only dates but other locale-specific formatting. e.g. in most of Europe excl.UK the comma (NOT the fullstop) is used as decimal point.

Also note that not all servers have got all LCID's available but you should be OK selecting between US, UK and AU.

HTH
I have this same problem dealing with a MySql database located on a SUN box and I am developing on an IIS 5.0 box.
The following code should turn 12/31/2002 in to 2002/12/31 or however you need to format the date.
Here is what I did in ASP.
Create a function:

FUNCTION dateEncode(xdate)
  xyear = datepart('yyyy',xdate)  
  xmonth = datepart('m',xdate)
  xday = datepart('d',xdate)
  dateEncode = xyear & "/" & xmonth & "/" & xday
END FUNCTION

xmySqlDate = dateEncode(NOW)
ASKER CERTIFIED SOLUTION
Avatar of ActiveMedia
ActiveMedia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For dd/mm/yyyy try this:

<% Dim ThisDay, ThisMonth, ThisYear, ThisDate

ThisDay = Day(Date())
ThisMonth = Month(Date())
ThisYear = Year(Date())
ThisDate = ThisDay & "/" & ThisMonth & "/" & ThisYear

Response.Write("ThisDate")%>


I am unsure of this but can you just call the Date function and put in the format you want?
Eg: ThisDate = Date(dd/mm/yyyy)



Avatar of DCPAus

ASKER

Is there a way to remotely check what the regional settings are for your server

DCP
Yes, include this line in a this script you upload to the server:

<%
   response.write "Session.LCID=" & session.LCID
%>

Did you try out the previous script I suggested?
<%
session.LCID=3081
response.write "today is " & date() & " in Australian format 3081<br>"
%>

What was the result?

HTH
Avatar of DCPAus

ASKER

Al the answers provided on this page were good, but the majority of them I had tried in a variety of formats, whereas the LCID issue as well as the 4guysfromrolla link, although not the complete answer, gave me a new insite on this issue and is helping me save my problem.

I have noticed though that although the LCID formats the date in the country format you require it still take certain formatting requirements from the regional settings of the server

Thanks to everyone who contributed.