Currently I am working with a JavaScript project (chat application using node). I have to display the time and date along with chat message. If the message is received on today, only needs to show the current time and if the message was received on previous days, need to display date along with time. My current problem is that, how can I compare the current date with message received date. For getting the current date I have used the bleow function
var dt = new Date();
The above code returns current date as
Thu May 04 2017 10:27:12 GMT+0530 (IST)
But the date obtained from mySql db for the message is like:
2017-05-04T04:26:37.000Z
I dont have any provision to told back-end developers to change the format of date they send. So now what can I do? The way I am going to do is like this
if(dt>historyDate){
// print the time only
}
else{
//print date and time
}
In the above code, dt is the current date and time and historyDate is date and time send from DB. So how can I compare the two dates? If any more details need, please comment.