Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


10.3.11 cmpDate (compares date)

Syntax

cmpDate  date1  {eq|ne|ge|gt|le|lt}  date2

Description

This command compares 2 days specified for arguments.

This command outputs 1 in the following cases:

This command outputs 0.

Arguments

date1

This command specifies the character string indicating date.

date2

This command specifies the character string indicating date.

Syntax of date with absolute date in the date command can be specified for date (Example: yyyy/mm/dd, yyyy-mm-dd, yyyymmdd, mm/dd/yyyy).

eq

This command determines that date 1 is equal to date 2.

ne

This command determines that date 1 is not equal to date 2.

ge

This command determines that date 1 is not less than date 2.

gt

This command determines that date 1 is larger than date 2.

le

This command determines that date 1 is not greater than date 2.

lt

This command determines that date 1 is less than date 2.

Output to the standard output

1 or 0.

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

cmpDate 2016/05/02 eq 2016/05/02     # "1" is output.
cmpDate 2016/05/02 ne 2016/05/02     # "0" is output.
cmpDate 20160505 ge 20160502         # "1" is output.
cmpDate 20160101 gt 20160502         # "0" is output.
cmpDate 20160505 le 20160502         # "0" is output.
cmpDate 20160101 lt 20160502         # "1" is output.

# If the date indicated by the variable date1 is different from the date indicated by date2, return 1.
result=$(cmpDate "$date1" ne "$date2")
if [[ $result -eq 1 ]]; then
  return 1
fi