Date Format Problem Cookie / Now()

Discussion in 'ASP General' started by Ian, Apr 2, 2004.

  1. Ian

    Ian Guest

    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.
     
    Ian, Apr 2, 2004
    #1
    1. Advertising

  2. Ian

    J. Baute Guest

    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.

    "Ian" <> wrote in message
    news:qIebc.554$...
    > 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. Baute, Apr 5, 2004
    #2
    1. Advertising

  3. Ian

    Ian Guest

    > 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
     
    Ian, Apr 5, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candy
    Replies:
    2
    Views:
    1,172
    Janaka
    Feb 18, 2004
  2. =?Utf-8?B?UmV6YQ==?=
    Replies:
    1
    Views:
    2,943
    Raterus
    Feb 27, 2004
  3. DC
    Replies:
    5
    Views:
    3,009
    Brendan Reynolds
    Jul 1, 2005
  4. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,279
    Michael Borgwardt
    May 30, 2004
  5. Une bévue

    problem with date and date/format

    Une bévue, Mar 10, 2006, in forum: Ruby
    Replies:
    3
    Views:
    111
    Une bévue
    Mar 12, 2006
Loading...

Share This Page