Go to main content

datediff

Date difference

DATEDIFF

NAME

datediff - Difference between two dates

SYNOPSIS

datediff(date1, date2[, mode: mode])

DESCRIPTION

Return the difference between 2 dates. The difference is in day, hour, min sec, week or year.

By default its the difference in day

KNOWN ISSUES

An error will be thrown if date1 or date2 is a date before 1970-01-01

PARAMETERS

date1 (string): A valid standard date or datetime string. Ex: "2023-01-18" or "2023-01-18 10:10:10"

date2 (string): A valid standard date or datetime string. Ex: "2023-01-18" or "2023-01-18 10:10:10"

mode (int - optional): Unit of the returned value:

  • 0: DAY (Default)
  • 1: HOUR
  • 2: MINUTE
  • 3: SECOND
  • 4: WEEK
  • 5: YEAR
                    

EXAMPLES

datediff("2016-01-05", "2016-01-06", mode: 0); // Return 1
datediff("2016-01-05", "2016-01-06", mode: 1); // Return 24
datediff("1999-01-01 12:00:00", "1999-01-01 13:00:00", mode: 2); // Return 60
datediff("1999-01-01 12:01:00", "1999-01-01 12:02:10", mode: 3); // Return 70
datediff("1999-01-01", "1999-01-15", mode: 4); // Return 2
datediff("1970-01-01", "2000-01-01", mode: 5); // Return 30
datediff("1969-01-01", "2000-01-01", mode: 5); // ERROR 

 

SEE ALSO

 

AUTHOR

Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

Edit

© 2024 extenso Inc. All rights reserved.