The date command

dateThis command  writes the current date and time to standard output if called with no flags or with a flag list that begins with a + (plus sign). Otherwise, it sets the current
date. Only a root user can change the date and time. The date command prints out the usage message on any unrecognized flags or input.

The following formats can be used when setting the date with the Date parameter:
* mmddHHMM[YYyy]
* mmddHHMM[yy]

The variables to the Date parameter are defined as follows:
Item
Description
mm
Specifies the month number.
dd
Specifies the number of the day in the month.
HH
Specifies the hour in the day (using a 24-hour clock).
MM
Specifies the minute number.
YY
Specifies the first 2 digits of the year.

Note: If you do not specify the first 2 digits of the year, values in the range 70 – 99 refer to the twentieth century, 1970 – 1999 inclusive, and values in the range 00 – 37
refer to years in the twenty-first century, 2000 – 2037 inclusive.
yy
Specifies the last 2 digits of the year.

Note: The date command accepts a 4-digit year as input. For example, if a 4-digit year is specified, the date command tries to set the year to YYyy and fails for values that
are out of range (less than 1970 and greater than 2105). For years in the range 2038 – 2105, specify the year in the yyyy format.

The current year is used as the default value when the year is not specified. The system operates in Coordinated Universal Time (CUT).

If you follow the date command with a + (plus sign) and a field descriptor, you can control the output of the command. You must precede each field descriptor with a % (percent
sign). The system replaces the field descriptor with the specified value. Enter a literal % as %% (two percent signs). The date command copies any other characters to the output
without change. The date command always ends the string with a new-line character.

The following table lists the main literals that can be used to output formats to date:

LiteralDescription
% ToAbbreviated name of the day
% AFull name of the day
% BAbbreviated month name
% BFull month name
% CDate and Time
% CFirst two digits of the year, say 20, 2007
% DDay of the month with two digits, eg 01
% DLike indicate% m /% d /% y
% EDay of the month with one or two digits, example 1, 10
% FComplete, the same date as% Y-% m-% d
% Hb As%
% HTime in 24-hour format with two digits (00..23)
% ITime in 12-hour format with two digits (01..12)
% JDay of year (001..366)
% KTime in 24-hour format with one or two digits (0..23)
% LTime in 12-hour format with one or two digits (1..12)
% MTwo-digit month (01..12)
% MWith double-digit minutes (00..59)
% RFull Time in 12-hour format (eg 1:23:45)
% RHours and minutes in 24-hour format, the same as% H:% M
% SSeconds since 01 / Jan / 1970 00:00:00 (epoch date)
% STwo digit seconds (00..60)
% TFull Time in 24-hour format (eg 13:23:45)
% UWeekday number (1..7, 1 is Monday)
% UNumber of the week in the year, Sunday, first day of week (00..53)
% VNumber of the week in the year, Monday first day of week (01..53) Format ISO
% WWeekday number (0..6, 0 is Sunday)
% WNumber of the week in the year, Monday first day of week (00..53)
% AndLast two digits of the year
% YCutro digit year
% ZTime or numeric time zone
% ZAlphabetical zone or time zone abbreviation

Some examples

Unix_Tricks> date +%B/%A/%d/%y
 June/Sunday/24/07
Unix_Tricks> date +%d%m%y
 240607
Unix_Tricks> cat lala.txt
 Unix_Tricks> date
 Sun June 24 22:01:28 CDT 2007
Unix_Tricks> date +%a
 dom
Unix_Tricks> date +%A
 Sunday
Unix_Tricks> date +%B%A
 JuneSunday
Unix_Tricks> date +%B-%A
 June-Sun
Unix_Tricks> date +%A-%B%-d
 June-Sunday-24
Unix_Tricks> date +%B-%A-%d-%Y
 June-24-2007-Sun
Unix_Tricks> date +%B/%A/%d/%y
 June/Sunday/24/07
Unix_Tricks> date +%d%m%y
 240607
Unix_Tricks>

Leave a Reply

Your email address will not be published.