1

i am using nodejs to connet to mySql Db. using node is ma able to retrieve all tables . Node is used as a backend with express.

I have a route http://localhost:3000/getALL

when i consume this i get all the data in JSON format. but i am having issues converting mySql time to JS object

[{"file_name":"150412-001070",
"date_time":"2015-07-21T13:11:55.000Z",
"polpospercent":68.95,"polnegpercent":31.05,
"Anger":6.58,
"Surprise":32.87,
"Sadness":32.87,
"Joy":4.59,
"Disgust":13.84,
"Fear":9.26,
"file_ts":"2014-04-26T22:03:00.000Z"}]

I need to convert file_ts to JS date and perform sort on it by Date. This is also not sorted on angularjs ngTable.

2
  • I suggest having a look at sailsjs. Commented Jul 23, 2015 at 4:50
  • 1
    what's wrong with the built-in Date method? new Date("2014-04-26T22:03:00.000Z") do also note that you can sort such ISO strings as text since they all have leading zeros and most-significant digits first. lastly, it's better for more reasons than not to sort in msql, order by file_ts... Commented Jul 23, 2015 at 4:57

1 Answer 1

1

Just use Moment.js:

moment(date,'YYYY-MM-DD HH:mm:ss ZZ').format('MM-DD-YYYY [or whatever]');

Since it's ISO standard though, you should be able to just do:

moment(date).format('MM-DD-YYYY [or whatever]');
Sign up to request clarification or add additional context in comments.

2 Comments

why use moment for an ISO date? i can see for something like "12-10-95", but for ISO?
Looked to me like OP wants to format it. But you're right, new Date(date) works just fine too.

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.