Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > sql date to js

Reply
Thread Tools

sql date to js

 
 
aamirghanchi@yahoo.com
Guest
Posts: n/a
 
      09-19-2006
Hi,

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"

Thanks

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      09-19-2006
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.
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      09-20-2006
JRS: In article <. com>,
dated Tue, 19 Sep 2006 08:32:48 remote, seen in
news:comp.lang.javascript, posted :
>
>//where as sqlDate is a string of the format "yyyy-mm-dd hh:mm:ss.0"


BTW, that's a subset of an XML/.NET format, which you could have found
out how to deal with via the FAQ, at

<URL:http://www.merlyn.demon.co.uk/js-date3.htm#XML>

And ISO 8601 is in the previous section.

It's a good idea to read the newsgroup and its FAQ.
--
© 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.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-21-2006
JRS: In article <>, dated
Wed, 20 Sep 2006 23:44:43 remote, seen in news:comp.lang.javascript, Jim
Davis <> posted :
><> wrote in message
>news: oups.com...


>> 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"

>
>My Date Extension library will convert that (now). ISO 8601 dates have the
>date and time segments separated by a "T" - I just had to update it to also
>accept a space.


Are you quite sure that segments are necessarily separated by a "T"?

In ISO 8601:2000 - I've studied a final draft - the T was mandatory.
But I've been led to believe that a space is now permissible - I've not
seen ISO 8601:2004. It would be a pity to mislead others.

On the assumption that the input string is supposed to contain exactly
one date-time with separated fields (but perhaps not exclusively), ISTM
appropriate to make at least the date separator wild (RegExp dot), and
perhaps to make the "T" position accept more characters (for example,
allowing for CR LF whitespace), as that only needs \D+ .

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP General 11 11-08-2003 11:24 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57