date

set and display date and time 

Command, KornShell Built-in


SYNOPSIS

date [-ctuU] [timespec]

date [-cuU] [+format]


DESCRIPTION

date either displays the operating system's idea of the current date and time or sets it to a new value. The following example shows the default format of the date:

Wed Feb 26 14:01:43 EST 1998

Options

-c 

sets or displays the date and time according to Greenwich Mean Time (Coordinated Universal Time) using CUT as the time zone name.

-t 

specifies that the BSD format is used when setting the date and time.

-u 

sets or displays the date and time according to Greenwich Mean Time (Coordinated Universal Time) using GMT as the time zone name.

-U 

sets or displays the date and time according to Coordinated Universal Time using UTC as the time zone name.

Setting Date and Time

date also accepts an argument in one of two forms. If the argument does not begin with +, date assumes it is a timespec to set the date and time. The timespec can have the form

[[mm]dd]hhmm[.ss]

or

mmddhhmmyy[.ss]

where mm is the optional number of the month (01-12), dd is the optional day of the month, hh is the hour in 24 hour format (required) mm is the minutes (required), yy is the optional last 2 digits of the year, and ss is the optional seconds.

date uses these values to set the date and time.

Note:

You must specify the hours and the minutes; other arguments are optional. The year can be specified only if you have specified the month and day.

The -t option allows you to use the BSD date format, which is:

[[[[cc]yy]mm]dd]hhmm[.ss]

where cc is the optional first 2 digits of the year.

Displaying Date and Time

If the argument to date begins with a + character, date uses format to display the date. date writes all characters in format, with the exception of the % and the character which immediately follows it, directly to the standard output. After date exhausts the format string, it outputs a newline character. The % character introduces a special format field similar to the printf() function in the C library (see Field Descriptors).

Field Descriptors

%A 
the full weekday name in the current locale (for example, Sunday, in the POSIX locale).
%a 
the abbreviation for the weekday in the current locale (for example, Sun, in the POSIX locale).
%B 
the full month name in the current locale (for example, February, in the POSIX locale).
%b 
the abbreviation for the month name in the current locale (for example, Feb, in the POSIX locale).
%C 
the first two digits of the year (19 or 20).
%c 
the appropriate representation of the date and time in the current locale.
%D 
the date in the form mm/dd/yy.
%d 
the two-digit day of the month as a number (01 to 31).
%e 
the day of the month in a two-digit, right-justified, blank-filled field ( 1 to 31).
%H 
the hour in the 24-hour clock representation (00 to 23).
%h 
the same as %b.
%I 
the hour in the 12-hour clock representation (01 to 12).
%j 
the numeric day of the year (001 to 366).
%M 
the minute (00 to 59).
%N 
the nanoseconds. (000000000 to 999999999)

Note:
Because the resolution of the Win32 GetSystemTimeAsFileTIme() API is 100 nanoseconds, the last two digits of the %N value displayed are 0.

%m 
the month number (01 to 12).
%n 
a newline character.
%p 
the equivalent of AM or PM in the current locale.
%R 
the 24-hour time (for example, 14:53).
%r 
the 12-hour time in the current locale's equivalent of AM/PM notation (for example, 11:53:29 AM in the POSIX locale).
%S 
the seconds (00 to 61). Note that there is an allowance for two leap seconds.
%s 
seconds since the Epoch (00:00:00 UTC, January 1, 1970).
%T 
the 24-hour time (for example, 14:53:29).
%t 
a tab character.
%U 
the week number in the year, with Sunday being the first day of the week (00 to 53). All days before the first Sunday of the new year are in week 0.
%u 
the weekday number with Monday being 1 and Sunday being 7.
%V 
the week number in the year, with Monday being the first day of the week (01 to 53). If the week containing January 1 has four or more days in the new year, it is week 1 of the new year; otherwise it is week 53 of the previous year.
%W 
the week number in the year, with Monday being the first day of the week (00 to 53). All days before the first Monday of the new year are in week 0.
%w 
the weekday number, with Sunday being 0 and Saturday being 6.
%X 
the appropriate time representation in the current locale.
%x 
the appropriate date representation in the current locale.
%Y 
the four-digit number of the year (for example, 1998).
%y 
the two-digit year (offset from %C).
%Z 
the time zone name (for example, EDT).
%z 
equivalent to %Z.
%% 
a percent-sign character.

The date command also supports the following modified field descriptors to indicate a different format as specified by the locale indicated by LC_TIME. If the current locale does not support a modified descriptor, date uses the unmodified field descriptor value.

%EC 
the name of the base year (period) in the current locale's alternate representation.
%Ec 
the current locale's alternate date and time representation.
%EX 
the current locale's alternate time representation.
%Ex 
the current locale's alternate date representation.
%EY 
the full alternate year representation.
%Ey 
the offset from %EC (year only) in the current locale's alternate representation.
%Od 
the day of month using the current locale's alternate numeric symbols.
%Oe 
the day of month using the current locale's alternate numeric symbols in a two-character, right-justified, blank-filled field.
%OH 
the hour (24-hour clock) using the current locale's alternate numeric symbols.
%OI 
the hour (12-hour clock) using the current locale's alternate numeric symbols.
%OM 
the minutes using the current locale's alternate numeric symbols.
%Om 
the month using the current locale's alternate numeric symbols.
%OS 
the seconds using the current locale's alternate numeric symbols.
%OU 
the week number of the year (with Sunday as the first day of the week) using the current locale's alternate numeric symbols.
%Ou 
the weekday number using the current locale's alternate numeric symbols with Monday being 1 and Sunday being 7.
%OV 
the week number in the year using the current locale's alternate numeric symbols, with Monday being the first day of the week. If the week containing January 1 has four or more days in the new year, it is week 1 of the new year; otherwise it is week 53 of the previous year.
%OW 
the week number of the year (with Monday as the first day of the week) using the current locale's alternate numeric symbols.
%Ow 
the weekday as a number using the current locale's alternate numeric symbols with Sunday being 0 and Saturday being 6.
%Oy 
the year (offset from %C) using the current locale's alternate numeric symbols.


EXAMPLES

The command

date '+%a %b %e %T %Z %Y'

produces the date in the default format. For example,

Wed Feb 26 14:01:43 EST 1998

ENVIRONMENT VARIABLES

TK_USE_CURRENT_LOCALE 

When set, this environment variable causes months and days of the week to be displayed as defined in the current locale. By default, PTC MKS Toolkit utilities display months and days of the week in English.

TZ 

gives the time zone for date to use when displaying the times. This is ignored if you specify either the -c or the -u option. For more information on this variable, see timezone.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

1 

Failure due to any of the following:

— a bad date conversion
— a formatted date that was too long
— you do not have permission to set the date
2 

Usage error, including:

— an invalid command line option
— too many arguments on the command line

Possible error messages include:

Bad date conversion: "string

The date and/or time specified on the command line had an invalid format (for example, if the hour is greater than 24).

Bad format character x 

A character following % in the format string was not in the list of field descriptors.

No permission to set date 

The system has denied you the right to set the date.


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.

The -c option, the -t option, and the %s and %z format specifiers are extensions to both the POSIX and x/OPEN standards. The %R format specifier is an x/OPEN extension to the POSIX standard.

On 8.1/2012R2/10/2016/2019/11/2022, you can specify the current locale using the Regional Settings item of the Control Panel.


NOTES

date is provided as both an external utility and a built-in MKS KornShell utility.

On machines that have a time-of-day clock with battery backup, using date does not necessarily change this real-time clock. There is probably an operating system-specific command to achieve this.

The date command supplied with PTC MKS Toolkit should not be confused with the date command internal to the native command interpreter on Windows systems (that is, cmd.exe).


AVAILABILITY

PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC Windchill Requirements and Validation


SEE ALSO

Commands:
sh, touch

Miscellaneous:
timezone


PTC MKS Toolkit 10.4 Documentation Build 39.