Datepicker and tstamp problem
Hi everyone,
I have some problem with tstamp function. I have two input field with datepicker (#date_from and #date_to) and select fields with hour and minutes (#time_from_hour, #time_from_minute, #time_to_hour, #time_to_minute). My date format looks like this: 1/11/2012
I use this script to calculating tstamp from above fields:
- function compute() {
- var c = $('select#time_from_hour').val();
- var d = $('select#time_from_minute').val();
- var e = $('select#time_to_hour').val();
- var f = $('select#time_to_minute').val();
- var g = $('input#date_from').val();
- var h = $('input#date_to').val();
- date1= g.split("/");
- var timestamp = (new Date(date1[2],date1[1],date1[0],c,d).getTime()/1000) + 7200;
- $('#total_hour1').val(timestamp);
- date2= h.split("/");
- var timestamp = (new Date(date2[2],date2[1],date2[0],e,f).getTime()/1000) + 7200;
- $('#total_hour2').val(timestamp);
- var x = -$('input#total_hour1').val();
- var y = -$('input#total_hour2').val();
- var total_time = x - y;
- result = total_time / 86400;
- new_number = Math.ceil(result);
- if(isNaN(new_number)) {
- var new_number = 0;
- }
- $('#finish_day').val(new_number);
- }
That script should calculating finish day (
the difference between two dates). And here is a problem:
When I pick the 31/10/2012 the tstamp is: 1354335300 (Sat, 01 Dec 2012 04:15:00 GMT)
and when I pick up on the second field 1/11/2012 the tstamp is also 1354335300 (Sat, 01 Dec 2012 04:15:00 GMT).
The day and the month are wrong and the #finish_day = 0, and I don't know why?
Where is the problem?
I will be grateful for any help.
The working code you can find here:
http://jsfiddle.net/W7NHK/