Christopher Francisco
Christopher Francisco

Reputation: 16268

Getting time between dates

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

Upvotes: 0

Views: 49

Answers (2)

Hristo Ivanov
Hristo Ivanov

Reputation: 719

Easy as this:

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

returned value:

7006311072//Js time timestamp

Upvotes: 0

Assaf Lavie
Assaf Lavie

Reputation: 75963

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.

Upvotes: 1

Related Questions