Adding dates to an XML Node

Discussion in 'ASP General' started by news@chthonic.f9.co.uk, Jan 18, 2006.

  1. 9.co.uk

    9.co.uk Guest

    This had me stumped for ages yesterday, and since I solved it and can't
    find much reference to the problem, I thought I'd post here.

    I have various vbscript ASP pages that take an ADO recordset and dump
    it out as XML into the page so that clientside processes can use it and
    a number of XSLT stylesheets to present/filter/re-sort the data without
    a trip back to the server.

    Yesterday I noticed that one of the pages insisted on displaying the
    dates in US MM-DD-YYYY format. I'm in the UK and had thought I'd set
    all the locales correctly to use UK dates.

    Turns out I had, except for the following situation:

    If you take a variable that has a date in it and assign it directly to
    the .text attibute of a DOMNode object, it is converted to text in the
    US format, regardless of the system/user/whatever locales set. If you
    cstr() the date first, it will be converted correctly.

    set xmlDoc = server.createobject("MSXML2.DOMdocument.4.0")
    set xmlNode = xmlDoc.createElement("foo")

    session.LCID = 2057 'Force UK locale for all those elsewhere
    datevar = #2006/1/12# '12th January

    response.write("datevar = " & datevar & "<br>")
    xmlNode.text = datevar
    response.write("xmlNode.text = datevar, results in " & xmlNode.text &
    "<br>") ' results in "01/12/2006"
    xmlNode.text = cstr(datevar)
    response.write("xmlNode.text = cstr(datevar), results in " &
    xmlNode.text) ' results in "12/01/2006"

    In other words, perform the string conversion within VBscript, not
    within MSXML2. One for the ASPFAQ
     
    9.co.uk, Jan 18, 2006
    #1
    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. Replies:
    0
    Views:
    1,471
  2. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    870
    Rob Schieber
    Sep 30, 2005
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
  4. Martin Honnen

    Re: Reading XML Node-by-Node

    Martin Honnen, Nov 12, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    389
    Martin Honnen
    Nov 12, 2008
  5. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    199
    Mark Schupp
    Aug 9, 2004
Loading...

Share This Page