I have a rails-generated date, and a jQuery-generated date.
The rails date prints as such: 2002-10-27
and the jQuery date prints as such: Tue Aug 14 2001 00:00:00 GMT-0500 (CDT)
I want to check if the jQuery date is greater or less than the rails date. But no matter the dates, the jQuery date is always interpreted as larger than the rails date.
Why is that, and how can I successfully compare the two dates?
var year = 2001
var month = 9
month --
var day = 14
var date = new Date(year, month, day);
<% @date = Date.today - 18.years %>
if( date > <%= @date %> ) {
//this code is always executed, no matter what dates I choose
}
UPDATE:
Actually I just figured out the problem is that it only allows dates before 1969. I intended the code to only allow dates over 18 years old. Does anyone know why the difference?
UPDATE 2:
I tested the time output of October 5th, 2000 in my js console and rails consoles, and they give the same first six digits, but the js console adds three zeros.
var year = 2000
var month = 10
month --
var day = 5
var date = new Date(year, month, day);
date.getTime();
=> 970722000000
Date.new(2000,10,5).to_time.to_i
=> 970722000