0

In database time-stamp is saved as 2015-12-05 10:53:12 but when I fetch record using mysql query it return this time-stamp like 2015-12-05T10:53:12.000Z. Why? any issue?? please help.

2
  • They are the same thing. The difference is how they represented. Put them in new Date() and play with it. The details are in JavaScript docs. Commented Dec 16, 2015 at 6:56
  • @iam - for your reference timestamp format is YYYY-MM-DD HH:MM:SS[.fraction] when you fetch from database using mysql command. Commented Dec 16, 2015 at 7:07

3 Answers 3

2

In your database the timestamp is saved in binary numerical format. "2015-12-05 10:53:12" & "2015-12-05T10:53:12.000Z" are string representation of that value that you see in some application.

It's the same value and there's no issue to solve here.

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

3 Comments

but I want to convert it into look like Dec 16, 2015. Is it possible??
From within NodeJS? lookup javascript date to string on Google or something
dateFormat(result[i]['created'], "mmmm d, yyyy") returning "December 5, 2015". how to get "Dec 5, 2015"?
1

To convert your Date-Object (which is represented as ISOString with "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") you have to parse it after reading from the db.

In JavaScript you can do that by simply passing the string in the constructor, e.g. var myDate = new Date("2015-12-05T10:53:12.000Z")

With a custom format you could do it like this for example:

var dateString = "2015-12-05 10:53:12"; var date = Date.parse(dateString, "yyyy-MM-dd HH:mm:ss");

In order to represent it as "Dec 16, 2015" you have to parse it afterwards:

There are some good libraries for doing this (e.g. momentjs or with angularjs - date filters)

Without that you have do manually do it somehow like this (where you pass your date object created before):

  function parseDate(date) {
    var months = ['JAN','FEB','MAR','APR','MAY','JUN',
      'JUL','AUG','SEP','OCT','NOV','DEC'];
    return months[date.getMonth()]+" "+("0" + date.getDate()).slice(-2)+", "+date.getUTCFullYear();
  }

Comments

0

You can use MySQL's DATE_FORMAT, eg.

SELECT DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y'); -> 'Sunday October 2009'

http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format

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.