Date Format Problem Cookie / Now()

I

Ian

I have a problem I hope someone can point out where I am going wrong. I need
to store a date/time in a cookie ( ie the date a visitor last visited )
However the date format changes to US, despite LCID being set to UK. I have
googled extensively but can't work it out.

This is my code to give write the current date/time to screen:

<%
Session.LCID = 2057
Response.Write Now() & "<br>" &
Response.Write FormatDateTime(Now(),1)
%>

This produces the following in the browser as I would expect

02/04/2004 15:13:48
02 April 2004

However when I store the date/time in a cookie, then read it back in it
changes to US format
My code:

<%
Session.LCID = 2057
'store date in cookie
Response.Cookies("Visit")("LastVist") = Now()
Response.Cookies("Visit").Expires = DateAdd("yyyy", 1, Now())

'read date back in and write it to browser
Response.Write Request.Cookies("Visit")("LastVist") & "<br>" &
Response.Write FormatDateTime(Request.Cookies("Visit")("LastVist"),1)
%>

I would expect this to give the same result as above, before it was written
to the cookie, but it doesn't it gives :

4/2/2004 3:13:48PM
04 February 2004

Any ideas? Many thanks if you can help.
 
J

J. Baute

Cookies are stored as strings, so when you store Now() into that cookie, the
date is converted into a string automatically, and maybe that's where it
goes wrong. Try storing that date in a format that can't be misread, like
the ISO date format "yyyy-mm-dd HH:MM:ss".
When it's read from the cookie afterwards, VBScript will convert it to the
correct date no matter what LCID is used when in this format.
 
I

Ian

Cookies are stored as strings, so when you store Now() into that cookie,
the
date is converted into a string automatically, and maybe that's where it
goes wrong. Try storing that date in a format that can't be misread, like
the ISO date format "yyyy-mm-dd HH:MM:ss".
When it's read from the cookie afterwards, VBScript will convert it to the
correct date no matter what LCID is used when in this format.

I'll try that , many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top