10.3.14 getDateDiff (gets the number of elapsed days)
Syntax
getDateDiff [-m|-y] date1 date2
Arguments
- -m
-
This command outputs the difference of days in units of month.
For example, if date1 is May 10, 2016 and date2 is June 10, 2016, 1 is output. If date1 is May 10, 2016 and date2 is June 9, 2016, 0 is output.
- -y
-
This command outputs the difference of days in units of date.
For example, if date1 is 5/10/2015 and date2 is 5/10/2016, 1 is output. If date1 is 5/10/2015 and date2 is 4/10/2016, 0 is output.
For a leap year, 366 days are interpreted as one year. For years other than a leap year, 365 days are interpreted as one year.
If any of the aforementioned options is not specified, difference of days is output in units of days. If both of the aforementioned options are specified, the command finishes with an error.
- date1
-
This command specifies the character string indicating date.
- date2
-
This command specifies the character string indicating date.
Syntax of date can be specified with absolute date in the date command to date (Example: yyyy/mm/dd, yyyy-mm-dd, yyyymmdd, mm/dd/yyyy).
Output to the standard output
Character string indicating the difference of date.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
Not less than 1 |
Termination with an error |
Notes
Although the character string that can be specified for date1 and date2 is the same as that of the date format based on absolute date with the date command, whether the character string can be specified is not verified.
Examples
getDateDiff 2016/05/10 2016/06/10 # "31" is output. getDateDiff -m 2016/05/10 2016/08/20 # "3" is output. getDateDiff -y 2016/05/10 2018/06/10 # "2" is output. # Output the difference between the current date and the date indicated by variable date 1. getDateDiff $("${ADSH_DIR_CMD}date" +%Y%m%d) "$date1"