0

I'm trying to write a countdown and it should expires on a MySQL datetime value.

Using JavaScript I can get today's time using new Date()).getTime() but then how can I get the time difference from JS date and the MySQL datetime, assuming MySQL datetime value is in the future

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • is this what you are looking for - http://stackoverflow.com/questions/1787939/check-time-difference-in-javascript. – attila May 11 '14 at 19:38
  • The obvious solution would be to pass the MySQL datetime to javascript and parse it as a javascript date, then just subtract one from the other. – adeneo May 11 '14 at 19:39

2 Answers2

1

getTime() gives you the number of milliseconds since 1970-01-01.

Convert the MySQL datetime object to JS format, and then you can subtract the milliseconds and see the difference.

Community
  • 1
  • 1
Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203
0

Easy as this:

new Date('2014-08-01 00:00:00').getTime()-new Date().getTime()

returned value:

7006311072//Js time timestamp
Hristo Ivanov
  • 679
  • 8
  • 25