bicycle
bicycle

Reputation: 8430

Convert date to unix timestamp through jQuery datepicker

I want to check whether the entered dob is above 18th old. For that i want to convert to convert the entered date to the unix time stamp. I tried using:

$.datepicker.formatDate('@', $('#dob').val());

But it gives three additional zeros and also goes one day earlier. Like for "10/10/1967" it returns: -70369200000 while it should return: -70329600. How should i change it?

Upvotes: 2

Views: 12085

Answers (1)

Alnitak
Alnitak

Reputation: 339816

To get the Unix time out of a date picker use:

$(el).datepicker('getDate') / 1000;

However you should also note that the semantics of Date objects are not well defined for "negative" dates.

Upvotes: 8

Related Questions