469,286 Members | 2,522 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Adding dates to an XML Node

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

Jan 18 '06 #1
0 1036

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by netsurfer | last post: by
2 posts views Thread by Maersa | last post: by
9 posts views Thread by James Geurts | last post: by
reply views Thread by Chris Millar | last post: by
5 posts views Thread by jorgedelgadolopez | last post: by
1 post views Thread by Bart Steur | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.