date command (displays the system date and time)
- Organization of this page
Format
date [-u] [-d date-information-string | -r elapsed-seconds] [+format]
Description
This command displays the system date and time.
Arguments
- --date=date-information-string
-
Specifies the date and time to be displayed as a date-information string. If more than one information string is specified, the last string specified takes effect. For the supported date-information strings, see Date-information strings that can be specified in the -d option.
- -r elapsed-seconds
-
Specifies that the display is to be of the date and time after the amount of time specified by elapsed-seconds had elapsed since the beginning of the UNIX epoch (UTC January 1, 1970, 00:00:00). The value specified in elapsed-seconds can range from -1009875600 to 2147440447. The output result cannot be guaranteed if the specified value is outside this range.
- +format
-
Specifies a display format for the date and time using format specification codes. The format specification codes for the strftime function (OS's API) can be used. For details about the supported format specification codes, see Supported format specification codes, below.
If this argument is not specified, the display format for the date and time will be %Y/%m/%d %A %H:%M:%S %Z.
Supported format specification codes
In the argument that begins with a plus sign (+), you can specify the format specification codes for the strftime function (OS's API). These format specification codes vary according to the OS. For the format specification codes supported by your OS, see the information about the strftime function in the OS documentation.
The following table lists and describes the typical format specification codes that are supported by all OSs:
Format specification code |
Meaning |
---|---|
%a |
Abbreviation for the day of the week |
%A |
Full name for the day of the week |
%b |
Abbreviation for the month |
%B |
Full name for the month |
%c |
Date and time display based on the locale |
%d |
Day of the month as a decimal number (01 to 31) |
%H |
Time in the 24-hour clock (00 to 23) |
%I |
Time in the 12-hour clock (01 to 12) |
%j |
Number of days since the beginning of the year as a decimal number (001 to 366) |
%m |
Month as a decimal number (01 to 12) |
%M |
Minute as a decimal number (00 to 59) |
%p |
AM or PM based on the current locale |
%S |
Second as a decimal number. The range of values displayed varies according to the OS depending on support for leap seconds. |
%U |
Week as a decimal number (00 to 53). The first Sunday of the year begins the weeks. |
%w |
Day of the week as a decimal number (0 to 6, where 0 indicates Sunday) |
%W |
Week as a decimal number (00 to 53). The first Monday of the year begins the weeks. |
%x |
Date based on the current locale |
%X |
Time based on the current locale |
%y |
Last two digits of the year as a decimal number (00 to 99) |
%Y |
Year as four decimal digits |
%Z |
Time zone name. If the time zone is unknown, this information is not displayed. |
%% |
Percent symbol (%) |
Date-information strings that can be specified in the -d option
Specify as explained below the date-information string that you want the date command to display:
-
Specifying an absolute date only
The specified date and time are displayed.
-
Specifying a relative date only
The date and time shifted from the current date and time are displayed.
-
Specifying an absolute date combined with a relative date
The date and time obtained by shifting the date and time specified as an absolute date by the date and time specified as a relative date are displayed.
The elements of the date-information string can be specified as uppercase or lowercase letters. If a specified value is earlier than 1970-01-01 00:00:00 or later than 2038-01-19 03:14:07 in UTC, the command issues the error message date: Invalid date: specified-value and then terminates with an error. In AIX, if a specified value is later than 2038-01-19 03:14:07 in the local time zone, the command issues error message date: Invalid date: specified-value and then terminates with an error. If the null character is specified as the date-information string, the command displays 00:00:00 on the current date.
The following explains the permitted elements of a date-information string and the syntax.
-
Specifying absolute dates
The following table lists and describes the elements of a date-information string that specifies an absolute date.
Table 8‒6: Elements of date-information strings (specifying an absolute date) Type
Specifiable element#
Details
Year
Four-digit calendar year in decimal (YYYY)
Permitted values are from 1970 to 2038.
Last two digits of the calendar year in decimal (YY)
Permitted values are from 00 to 99.
For 69 to 99, 1969 to 1999 are assumed; for 00 to 68, 2000 to 2068 are assumed.
Month
Name of month (MONTH)
The following values can be specified:
-
January or Jan
-
February or Feb
-
March or Mar
-
April or Apr
-
May
-
June or Jun
-
July or Jul
-
August or Aug
-
September, Sept, or Sep
-
October or Oct
-
November or Nov
-
December or Dec
Month in decimal (MM)
Permitted values are from 01 to 12.
Day
Day of the month in decimal (DD)
Permitted values are from 01 to 31.
Hour
Time in 24-hour representation (hh)
Permitted values are from 00 to 23.
Time in 12-hour representation (hh)
Permitted values are from 01 to 12.
Minute
Minute in decimal (mm)
Permitted values are from 00 to 59.
Second
Second in decimal (ss)
Permitted values are from 00 to 59.
am/pm
am and pm (am | a.m. | pm | p.m.)
The following values can be specified after the time:
-
am or a.m.
-
pm or p.m.
Time zone
Time zone name (ST)
The following values can be specified:
-
UTC or UT: Coordinated Universal Time
-
GMT: Greenwich Mean Time (UTC + 0 hours)
-
WET: Western European Time (UTC + 0 hours)
-
AST: Atlantic Standard Time (UTC - 4 hours)
-
EST: Eastern Standard Time (UTC - 5 hours)
-
CST: Central Standard Time (UTC - 6 hours)
-
MST: Mountain Standard Time (UTC - 7 hours)
-
PST: Pacific Standard Time (UTC - 8 hours)
-
HST: Hawaii Standard Time (UTC - 10 hours)
-
WAT: West Africa Time (UTC + 1 hours)
-
CET: Central European Time (UTC + 1 hours)
-
MET: Middle European Time (UTC + 1 hours)
-
CAT: Central Africa Time (UTC + 2 hours)
-
EET: Eastern European Time (UTC + 2 hours)
-
JST: Japan Standard Time (UTC + 9 hours)
-
GST: Guam Standard Time (UTC + 10 hours)
-
NZST: New Zealand Standard Time (UTC + 12 hours)
Military time zone (ST)
The following values can be specified:
-
A: UTC - 1 hour
-
B: UTC - 2 hours
-
C: UTC - 3 hours
-
D: UTC - 4 hours
-
E: UTC - 5 hours
-
F: UTC - 6 hours
-
G: UTC - 7 hours
-
H: UTC - 8 hours
-
I: UTC - 9 hours
-
K: UTC - 10 hours
-
L: UTC - 11 hours
-
M: UTC - 12 hours
-
N: UTC + 1 hour
-
O: UTC + 2 hours
-
P: UTC + 3 hours
-
Q: UTC + 4 hours
-
R: UTC + 5 hours
-
S: UTC + 6 hours
-
T: UTC + 7 hours
-
U: UTC + 8 hours
-
V: UTC + 9 hours
-
W: UTC + 10 hours
-
X: UTC + 11 hours
-
Y: UTC + 12 hours
-
Z: UTC
Specification of time from UTC (+hhmm | -hhmm | +hh:mm | -hh:mm)
The time from UTC can be specified in the format +hhmm, -hhmm, +hh:mm, or -hh:mm (mm and :mm can be omitted).
Time zone (summer time)
Time zone (summer time) (DT)
The following values can be specified:
-
BST: British Summer Time (GMT + 1 hours)
-
ADT: Atlantic Daylight Time (AST + 1 hours)
-
EDT: Eastern Daylight Time (EST + 1 hours)
-
CDT: Central Daylight Time (CST + 1 hours)
-
MDT: Mountain Daylight Time (MST + 1 hours)
-
PDT: Pacific Daylight Time (PST + 1 hours)
-
MEST: Middle European Summer Time (MET + 1 hours)
-
NZDT: New Zealand Daylight Time (NZST + 1 hours)
Daylight saving time
Daylight saving time (DST)
You can specify DST for daylight saving time. When DST is specified together with a time zone, the specified time zone's standard time is advanced by one hour regardless of the specified date, time, and time zone. DST cannot be specified alone without a time zone specification.
- #
-
Letters in parentheses, such as YY and MONTH, correspond to the syntax explained in the table below.
The following table explains the syntax for date-information strings when an absolute date is specified.
Table 8‒7: Syntax for date-information strings (when specifying an absolute date) Type#
Syntax
Details
Date specification
[YY]YYMMDD
Define year, month, and day in this order without spaces. The first two digits of the year can be omitted.
[YYYY/]MM/DD
Define year, month, and day in this order separated by /. If the year is omitted, the current year is assumed.
MM/DD[/[YY]YY]
Define month, day, and year in this order separated by /. If the year is omitted, the current year is assumed. The first two digits of the year can be omitted.
[YY]YY-MM-DD
Define year, month, and day in this order separated by -. The first two digits of the year can be omitted.
DD MONTH [[YY]YY]
Define day, the formal name for month (or abbreviation for month), and year in this order separated by the space. If the year is omitted, the current year is assumed. The first two digits of the year can be omitted.
MONTH DD [,[YY]YY]
Define the formal name for month (or abbreviation for month), day, and year in this order. Separate the formal name for month (or abbreviation for month) and day with the space and separate day and year with the comma (,). If the year is omitted, the current year is assumed. The first two digits of the year can be omitted.
DD[-]MONTH[[-][YY]YY]
Define day, the formal name for month (or abbreviation for month), and year in this order without any spaces or separator or with the - as the separator. If the year is omitted, the current year is assumed. The first two digits of the year can be omitted.
MONTH-DD-[YY]YY
Define the formal name for month (or abbreviation for month), day, and year in this order separated by -. The first two digits of the year can be omitted.
MONTH DD [[YY]YY]
Define the formal name for month (or abbreviation for month), day, and year in this order separated by the space. If the year is omitted, the current year is assumed. The first two digits of the year can be omitted.
Time specification
hh[mm]
hh [am | a.m. | pm | p.m.]
Define the hour and minute in this order without any spaces.
The value for minute can be omitted.
If only a value for hour is defined, am (a.m.) or pm (p.m.) can be specified following a space.
If you are specifying am (a.m.) or pm (p.m.), use the 12-hour representation for the time.
hh:mm[:ss] [am | a.m. | pm | p.m.]
Define hour, minute, and second in this order separated by colons (:).
The value for second can be omitted.
You can specify am (a.m.) or pm (p.m.) following the definition of hour, minute, and second and a space.
If you are specifying am (a.m.) or pm (p.m.), make sure that the definition of hour, minute, and second does not exceed 12:59:59.
hh:mm[:ss] [+hh[mm] | -hh[mm] | +hh[:mm] | -hh[:mm]]
Define hour, minute, and second in this order separated colons (:).
The value for second can be omitted.
You can specify +hhmm, -hhmm, +hh:mm, or -hh:mm following the definition of the hour, minute, and second and a space.
Time zone
ST [DST]
ST [+hh[mm] | -hh[mm] | +hh[:mm] | -hh[:mm]]
Specify a time zone. You can specify DST, +hhmm, -hhmm, +hh:mm, or -hh:mm following the time zone and a space.
DT
Define a time zone (summer time). The time zone (summer time) cannot be specified together with DST, +hhmm, -hhmm, +hh:mm, or -hh:mm.
- #
-
The same type cannot be defined multiple times, but different types can be combined.
If only a date is specified, 00:00:00 is assumed for the time.
If only hour (hh) is specified, minute (mm) and second (ss) are set to 0 on the current date.
If only hour (hh) and minute (mm) are specified, second (ss) is set to 0 on the current date.
-
-
Specifying relative dates
The following table lists and describes the elements of a date-information string that specifies a relative date.
Table 8‒8: Elements of date-information strings (specifying a relative date) Specifiable element#
Details
Number of years and months to be shifted (DATE)
Specify the following values:
-
year or years: Number of years to be shifted
-
month or months: Number of months to be shifted
You can specify a numeric value (NUM) before this value. If the numeric value (NUM) is omitted, 1 is assumed.
Number of days to be shifted (DATE)
Specify the following values:
-
fortnight or fortnights: Shift by two weeks (14 days)
-
week or weeks: Shift by one week (7 days)
-
day or days: Shift by day(s)
-
tomorrow: Tomorrow (one day later)
-
yesterday: Yesterday (one day ago)
-
today: Today (0 day)
-
now: Now (0 day)
You can specify a numeric value (NUM) before this value. If the numeric value (NUM) is omitted, 1 is assumed.
Number of hours and minutes to be shifted (DATE)
Specify the following values:
-
hour or hours: Number of hours to be shifted
-
minute, min, or minutes: Number of minutes to be shifted
You can specify a numeric value (NUM) before this value. If the numeric value (NUM) is omitted, 1 is assumed.
Number of seconds to be shifted (DATE)
Specify the following value:
-
second, sec, or seconds: Number of seconds to be shifted
You can specify a numeric value (NUM) before this value. If the numeric value (NUM) is omitted, 1 is assumed.
Number of days of week to be shifted (DAY)
Specify the following values:
-
Monday or Mon
-
Tuesday, Tue, or Tues
-
Wednesday, Wed, or Wednes
-
Thursday, Thu, Thur, or Thurs
-
Friday or Fri
-
Saturday or Sat
-
Sunday or Sun
You can specify a numeric value (NUM) before this value to specify the NUM-th day of the week. If the numeric value (NUM) is omitted, 1 is assumed. If neither 1 nor a numeric value (NUM) is specified, the next day of the week is assumed. Neither signs (+|-) nor the before and after specification (ago) can be specified.
Numeric value specification (character string) (NUM)
Specify the following values:
-
last: -1
-
this: 0
-
next: 1
-
first: 1
-
third: 3
-
fourth: 4
-
fifth: 5
-
sixth: 6
-
seventh: 7
-
eighth: 8
-
ninth: 9
-
tenth: 10
-
eleventh: 11
-
twelfth: 12
A numeric value (NUM) cannot be specified before this value.
Numeric value specification (number) (NUM)
Permitted values are from 0 to 2147483647.
Sign (+|-)
You can specify the following values before the numeric value (NUM):
-
+: Positive
-
-: Negative
If the sign is not followed by a numeric value, the sign is ignored.
Before and after specification (ago)
Specify the following value:
-
ago: Ago -
The positive or negative sign for the date-information string specified immediately before ago is reversed (positive becomes negative and negative becomes positive).
- #
-
Letters in parentheses, such as NUM and DATE, correspond to the syntax explained in the table below.
The table below explains the syntax for date-information strings when a relative date is specified. Shift in date and time can be combined with shift in day of week.
Table 8‒9: Syntax for date-information strings (when specifying a relative date) Type
Syntax
Details
Shift in date and time
[[+ | -]NUM] DATE [ago]
Specify the amount of time to be shifted from the current date and time or the date and time specified as a date-information string.
Multiple elements can be specified by separating them with the space.
For the elements that can be combined, see Table 8-8 Elements of date-information strings (specifying a relative date).
Shift in day of week
[NUM] DAY
DAY[,]
Specify a day of the week. Only one value can be specified.
A day of the week immediately preceded by a numeric value (NUM) defines the NUM-th day of the week. If the numeric value (NUM) is omitted, the next day of the week is assumed.
The specified day of the week can be followed by a comma (,) or a space, and then by another definition of shift in date and time.
-
-
Other specification
The following table describes other elements of date-information strings.
Table 8‒10: Elements of date-information strings (other) Specifiable element
Details
Comment
Specify any character string as a comment by enclosing it in parentheses (( )) within a date-information string. If ( ) is nesting within another ( ), the character string specified in the inner ( ) is ignored.
If only a left parenthesis (() is specified, all characters following the left parenthesis are ignored.
The specified absolute and relative date and time values are obtained in the order shown below. In steps 2 through 4, if the value converted to seconds is outside the range from 0 to 2147483647, an error might result regardless of the final results.
-
Obtains the current date and time or the date and time specified as an absolute date.
-
Adds the shift in day of week specified as a relative date to the value obtained in step 1. If date specification is specified as an absolute date, the number of days of week to be shifted (DAY) is not added, if specified.
-
Adds or subtracts all results obtained based on the specified number of years and months to be shifted (DATE) as a relative date to or from the value obtained in step 2.
-
Adds or subtracts all results obtained based on the specified number of days to be shifted (DATE), number of hours and minutes to be shifted (DATE), and number of seconds to be shifted (DATE) specified as a relative date to or from the value obtained in step 3.
Steps 2 through 4 obtain the amount to be shifted from the date and time subject to calculation.
For example, if the current date and time is 2014-04-30 at 10:10:10 and date -d "Fri, 1 year 1 month 1 day 1 hour 1 min 1 sec" is specified, the following calculation occurs:
- 1. Obtain the current date and time.
-
The result is 2014-04-30 (Wednesday) at 10:10:10.
- 2. Add the number of days from 2014-04-30 (Wednesday) to the next Friday.
-
The result is 2014-05-02 (Friday) at 10:10:10.
- 3. Add 365 days and the number of days in May 2014.
-
The result is 2015-06-02 (Monday) at 10:10:10.
- 4. Add one day, one hour, one minute, and one second.
-
The result is 2015-06-03 (Tuesday) at 11:11:11.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 or greater |
Error termination |
Notes
-
If a format code specified in +format is outside the range of valid format codes of the strftime function, the specified value is output as is.
-
In Windows, if you specify a mixture of valid and invalid format codes, the specified values are output as is, without any format code conversion.
-
In UNIX, valid format codes are converted while the specified values are output as is for invalid format codes.
-
In Windows, if you specify the TZ environment variable, you must ensure that the value of the TZ environment variable matches the time zone set in the Date and Time control panel. If their values do not match, the correct date and time might not be displayed.
-
An unsupported argument that is specified in the command line is ignored.
-
If either of the following environment variables is specified, any option following an argument that begins with a plus sign (+) is ignored:
-
POSIXLY_CORRECT environment variable
-
ADSH_CMD_ARGORDER=seq environment variable
-
Usage examples
-
Display the default with no options specified.
C:\TEMP>%ADSH_OSCMD_DIR%\date 2011/05/09 Monday 02:03:05 JST
-
Specify the -u option to display the date and time in UTC (Coordinated Universal Time).
C:\TEMP>%ADSH_OSCMD_DIR%\date -u 2011/05/08 Sunday 17:03:11 UTC
-
Specify the -r option to display the date and time after a specified number of seconds had elapsed from the beginning of the UNIX epoch.
C:\TEMP>%ADSH_OSCMD_DIR%\date -r 1234567890 2009/02/14 Saturday 08:31:30 JST
-
Specify a display format for the date and time in the +operand argument.
C:\TEMP>%ADSH_OSCMD_DIR%\date "+%Y-%m-%d %H.%M.%S" 2011-05-09 02.10.02
-
Display the date of December 12 this year.
C:\TEMP>%ADSH_OSCMD_DIR%\date -d "12/12" 2011/12/12 Sunday 00:00:00 JST
-
Display the date that is three months and one day from the current date.
C:\TEMP>%ADSH_OSCMD_DIR%\date -d "3 months 1 day" 2011/08/10 Wednesday 00:00:00 JST
-
Display the date that was two days ago.
C:\TEMP>%ADSH_OSCMD_DIR%\date -d "2 days ago" 2011/05/07 Saturday 00:00:00 JST
-
Display the date that falls 100 days after 2011-05-01. This example uses the --date option to specify a date-information string.
C:\TEMP>%ADSH_OSCMD_DIR%\date --date="1-May-2011 100 days" 2011/08/09 Tuesday 00:00:00 JST
-
Display an option error message.
This message might vary depending on the platform on which the command is executed. The following shows an example in Windows:
C:\TEMP>%ADSH_OSCMD_DIR%\date -a date: illegal option -- a usage: date [-u] [-d string | -r seconds] [+format]