JRS: In article <. com>,
dated Tue, 19 Sep 2006 08:32:48 remote, seen in
news:comp.lang.javascript,
posted :
>is there a readily available function/script out there that would
>convert a datetime value from MS SQL server to a date javascript can
>understand.
>
>something
>var jsDate = new Date( func_SQL_TO_JS_Date(sqlDate) )
>
>//where as sqlDate is a string of the format "yyyy-mm-dd hh:mm:ss.0"
That's an ISO 8601 format.
Yes. Read the newsgroup FAQ; see below.
You should consider whether the SQL date/time is local or UTC, and
whether validation is needed. For unvalidated local, consider
function func_SQL_TO_JS_Date(sqlDate) {
return sqlDate.replace(/^(....).(..).(.{11}).*$/, "$1/$2/$3") }
For UTC, consider replacing $3 with $3Z or $3 UTC .
If you need to honour the fractional seconds treat them separately as
milliseconds and incorporate them after.
Alternatively, split the input into seven fields - .split(/\D/) - should
do it - and use new Date or Date.parse with six or seven arguments.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.