DateDiff(date1, date2) Last updated: 23. Mar 2023

Gets the difference timespan between two date / datetime objects.

Parameters

Name Type Description
date1 date or string First date to compare with.
If not date type it will try to convert to date.
date2 date or string Second date to compare with.
If not date type it will try to convert to date.

Returns

A timespan object.

With the following properties:

• Days - Stores the day component of the TimeSpan structure.
• Hours - Returns the hours component of the TimeSpan structure.
• Microseconds - Gets the component that represents microseconds in a TimeSpan instance
• Milliseconds - Stores the milliseconds component of the TimeSpan structure.
• Minutes - Retrieves the minutes component of the current TimeSpan instance.
• Nanoseconds - This property represents whole nanoseconds.
• Seconds - Represents the seconds component of the TimeSpan structure ranging from -59 to 59.
• Ticks - Represents the number of ticks in the current TimeSpan instance.
• TotalDays - Uses whole and fractional numbers to represent the total number of days in the TimeSpan instance.
• TotalHours - Gets the total number of hours in the current TimeSpan structure.
• TotalMicroseconds - Represents the total number of microseconds in the TimeSpan instance.
• TotalMilliseconds - The property gets the total number of milliseconds in the current instance.
• TotalMinutes - Returns the TimeSpan structure in minutes and uses both whole and fractional values.
• TotalNanoseconds - This property represents whole and fractional nanoseconds.
• TotalSeconds - Returns the value of the current TimeSpan instance as seconds.

Example

Code example (#JS)

#JS is mixed HTML (or other text file) with inline JavaScript with # starting and ending each inline statement.
#{
    let y2k = new Date("2000-01-01");
    let date2 = new Date("2027-11-12");

    let diff = docly.dateDiff(y2k, date2);
    
    write("Seconds: "+ diff.TotalSeconds + "\r");
    write("Minutes: " + diff.TotalMinutes + "\r");
    write("Days: " + diff.TotalDays + "\r");
}#

Output

The #JS code above produces the output shown below:
Seconds: 879292800
Minutes: 14654880
Days: 10177