N
news
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
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