2

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but it still doesn't solve the previous day issue. 10/12/1967 returns -70196400 while according to onlineconversion.com/unix_time.htm it should return -70156800
It's like the datepicker conversion is always 11 hours earlier
aaah wait, now that i think of it, it must be because of the time difference. timestamp is relative and not universal

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.