0

I'm still new to programming, and am having trouble converting this date. I'm using ajax with a chat application, and pull the date from SQL Server database record but can't seem to convert it. The line of code getting the date is simply:

var timeStart = results.d[i].CreateDate;

the result I get is: /Date(1365692153250)/

I tried adding 'new Date( )' before, and/or '.format(MMMM ...)' after. This is probably an easy one, but I've looked all over. Please let me know if any additional info is needed. Thanks.

4
  • Perhaps you can better coerce the server to produce a decent format? stackoverflow.com/questions/4075683/sql-server-create-date Commented Apr 11, 2013 at 15:17
  • 1
    That's a .Net serialized date, here's how: stackoverflow.com/questions/1016847/… Commented Apr 11, 2013 at 15:23
  • @mattmanser - that link helped. If I could mark your comment the answer, I would. Thank you Commented Apr 11, 2013 at 18:03
  • 1
    @deebs No problem, annoyingly SO converted the answer to a comment and I couldn't see how to undo it! Commented Apr 12, 2013 at 8:27

3 Answers 3

1

I think this question and answers will help you: Convert a Unix timestamp to time in JavaScript

You just need to convert your timestamp.

Good luck.

Sign up to request clarification or add additional context in comments.

Comments

1

You will want to construct a Date() and use the getters to build up the format. https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date

For passing in a format, you will want to include your own library, here is one solution for generating it: http://blog.stevenlevithan.com/archives/date-time-format

Comments

0

Thanks @mattmanser for this thread, which answered my question... Converting .NET DateTime to JSON

Solution:

var timeStart = results.d[i].CreateDate.replace(/\/Date\((-?\d+)\)\//, '$1');
var d = new Date(parseInt(timeStart));

I hate to 'answer my own question' but want to provide the solution to anyone else who may need it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.