mactruck
08-05-2002, 05:02 PM
Hi,
I am trying to create a code that will take a date and time entered by a user and calculate a date and time 1 hour prior. The code I have pieced together works most of the time, however it seems to have problems at the beginning of the month.
Here is my code:
function set_onlinedate()
{
ihours_in = eval(document.LogEntryForm.DHour_In.value);
iminutes_in = eval(document.LogEntryForm.DMinute_In.value);
var date_array=document.LogEntryForm.DepartureDate_In.value.split("-");
var new_date = new Date(date_array[0] ,date_array[1], date_array[2], ihours_in-1, iminutes_in, 0);
var year_out = new_date.getYear();
var month_out = new_date.getMonth();
var day_out = new_date.getDate();
var hour_out = new_date.getHours();
month_out = (month_out.toString().length < 2) ? "0" + month_out : month_out;
day_out = (day_out.toString().length < 2) ? "0" + day_out : day_out;
document.LogEntryForm.OnlineDate_In.value = year_out + '-' + month_out + '-' + day_out;
document.LogEntryForm.OHour_In.value = (hour_out.toString().length < 2) ? "0" + hour_out : hour_out;
document.LogEntryForm.OMinute_In.value = (iminutes_in.toString().length < 2) ? "0" + iminutes_in : iminutes_in;
alert("Verify that the Online Date and Time have been automatically entered correctly!");
}
The date and time is entered in the following format:
Date = yyyy-mm-dd
Hour = hh
Minute = mm
When I select a date of "2002-09-01" and a time of "00:15", I receive a date of "2002-08-30" and a time of "23:15". I should receive a date of "2002-08-31" and a time of "23:15".:confused:
Any help you can provide would be greatly appreciated. I am new to HTML and Java.
Thanks.
I am trying to create a code that will take a date and time entered by a user and calculate a date and time 1 hour prior. The code I have pieced together works most of the time, however it seems to have problems at the beginning of the month.
Here is my code:
function set_onlinedate()
{
ihours_in = eval(document.LogEntryForm.DHour_In.value);
iminutes_in = eval(document.LogEntryForm.DMinute_In.value);
var date_array=document.LogEntryForm.DepartureDate_In.value.split("-");
var new_date = new Date(date_array[0] ,date_array[1], date_array[2], ihours_in-1, iminutes_in, 0);
var year_out = new_date.getYear();
var month_out = new_date.getMonth();
var day_out = new_date.getDate();
var hour_out = new_date.getHours();
month_out = (month_out.toString().length < 2) ? "0" + month_out : month_out;
day_out = (day_out.toString().length < 2) ? "0" + day_out : day_out;
document.LogEntryForm.OnlineDate_In.value = year_out + '-' + month_out + '-' + day_out;
document.LogEntryForm.OHour_In.value = (hour_out.toString().length < 2) ? "0" + hour_out : hour_out;
document.LogEntryForm.OMinute_In.value = (iminutes_in.toString().length < 2) ? "0" + iminutes_in : iminutes_in;
alert("Verify that the Online Date and Time have been automatically entered correctly!");
}
The date and time is entered in the following format:
Date = yyyy-mm-dd
Hour = hh
Minute = mm
When I select a date of "2002-09-01" and a time of "00:15", I receive a date of "2002-08-30" and a time of "23:15". I should receive a date of "2002-08-31" and a time of "23:15".:confused:
Any help you can provide would be greatly appreciated. I am new to HTML and Java.
Thanks.