Sidebar

How do I convert a SQL Server Date to a Java Script Date?

0 votes
478 views
asked Mar 22, 2016 by (630 points)
I am pulling back data from a SQL Server database and converting to JSON before returing to a Java Script powered Client.

They would like the String in a Java Script Format.

1 Answer

+1 vote

The Java Script date is based on Unix / Epoch time, which is the number of seconds that have elapsed since 12AM 1st January 1970 (UTC).

This date conversion can be realised with a single line of code:

  • qie.deduceDate(<SQL Date>).getTime();

The key here is the Date.getTime() method, which will return the number of seconds between the epoch and argument date time intervals.

answered Mar 22, 2016 by (630 points)
...