Here is my code...

function buildTimer(second,minute,hour,day,month)
{

    if(getCookie('day') == "")
    {
        setCookie("month",month,1095);
        setCookie("day",day,1095);
        setCookie("hour",hour,1095);
        setCookie("minute",minute,1095);
        setCookie("second",second,1095);
    }
    
    
    var d = new Date();
    var curr_month = d.getMonth();
    if(month >= curr_month)
    {
        year = d.getFullYear();
    
    }
    else
    {
        year = d.getFullYear()+1;
    }
    
    var Bday = new Date(year, month, day, hour, minute, second, 0);
    var Today = new Date();
    
    var totaldays = daysBetween(Today, Bday);
    
    var time = (totaldays*86400) + (hour*3600) + (minute*60) + second;

    alert(time);
    
    CreateTimer(time);
}

AND here is the function that I used...

function daysBetween(date1, date2) {

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}

The code at the end alerts a certain number of seconds, but it is not even close to the time between the two dates.

What am I doing wrong?

var time_difference_in_seconds = (Today.getTime() - Bday.getTime()) / 1000;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.