Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Problem with Daylight Savings and Date/Time maybe?

1. ## Problem with Daylight Savings and Date/Time maybe?

Help,

I wrote this function below to compute/return the end date / time when passed a start date / time and duration. It works OK all year except today when I pass it :

start_date
"04/06/03"
start_time
"02:00"
"00:00:15"

It supposed to return '04/06/02_0215'
but it's not and is returning: '04/06/02_0115'

I'm sure it has to do with daylight savings time but don't know how to correct it, please help.

Thanks,
Ed

/*--------------------------------------------------------------*/
/* */
/* Adds a time to a start date and returns a date as the result */
/* start date - MM/DD/YY */
/* start time - HH:MM */
/* add time - DD:HH:MM */
/* returned - MM/DD/YY_HH:MM */
/* */
/* Example: */
/* var start_date = '12/30/01' */
/* var start_time = '23:00' */
/* var add_time = '01:02:15' */
/* */
/* */
/* end_date will be '01/01/02_0115' */
/* */
/*--------------------------------------------------------------*/

{

if(start_date.toUpperCase() == 'NOW')
{
var S_date = new Date() ;
}
else
{
var s_mon = start_date.substr(0,2) ;
var s_mon = s_mon.valueOf() - 1 ;
var s_day = start_date.substr(3,2) ;
var s_day = s_day.valueOf() -0 ;
var s_yr = start_date.substr(6,2) ;
var s_yr = s_yr.valueOf() - 0 ;
var s_yr = s_yr +2000 ;
var s_hr = start_time.substr(0,2) ;
var s_hr = s_hr.valueOf() - 0 ;
var s_min = start_time.substr(3,2) ;
var s_min = s_min.valueOf() - 0;
var S_date = new Date(s_yr,s_mon,s_day,s_hr,s_min) ;
}

var tot_mins = tot_hrs*60 + add_mins
var tot_ms = tot_mins*60000
//alert('tot hrs mins ms '+tot_hrs + ' '+tot_mins+' '+tot_ms)
E_date = new Date(S_date.valueOf() + tot_ms)

var mm = E_date.getMonth() + 1
var dd = E_date.getDate()
var yy = E_date.getFullYear() - 2000
var hr = E_date.getHours()
var mn = E_date.getMinutes()

if (mm <=9)
var mm = ("0" + mm + "/");
else
var mm = (mm + "/");
if (dd <=9)
var dd = ("0" + dd + "/");
else
var dd = (dd + "/");
if (yy <=9)
var yy = ("0" + yy);

if (hr <=9)
var hr = ("0" + hr + ":");
else
var hr = (hr + ":");
if (mn <=9)
var mn = ("0" + mn + "");
else
var mn = (mn + "");

new_date = mm+dd+yy+'_'+hr+mn

return new_date