• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

MAN PAGE> ‘date’ (8.4)

Jan30
2013
Written by Scott Rowley

Note that this man page is regarding date version ‘date (GNU coreutils) 8.4’, your mileage may vary when using other versions.

I’m going to expand this section to include examples of every entry from the man page. Note that some examples include additional commands to demonstrate the information we are working with.

NAME
date — print or set the system date and time

SYNOPSIS
date [OPTION]… [+FORMAT]
date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]

DESCRIPTION
Display the current time in the given FORMAT, or set the system date.

-d, –date=STRING
display time described by STRING, not ‘now’

date
Wed Jan 30 10:08:18 CST 2013
date -d "1 year ago"
Mon Jan 30 10:08:33 CST 2012

-f, –file=DATEFILE
like –date once for each line of DATEFILE

cat years.txt
1 year ago
2 years ago
3 years ago
date -f years.txt
Mon Jan 30 10:19:17 CST 2012
Sun Jan 30 10:19:17 CST 2011
Sat Jan 30 10:19:17 CST 2010


-r, –reference=FILE
display the last modification time of FILE

ls -al style.css
-rw-r--r--. 1 root root 427 Jan 28 14:36 style.css
date -r style.css
Mon Jan 28 14:36:24 CST 2013

-R, –rfc-2822
output date and time in RFC 2822 format

date -R
Wed, 30 Jan 2013 10:25:12 -0600

–rfc-3339=TIMESPEC
output date and time in RFC 3339 format. TIMESPEC=’date’, ‘seconds’, or ‘ns’ for date and time to the indicated precision.

date --rfc-3339=date
2013-01-30
date --rfc-3339=seconds
2013-01-30 10:29:36-06:00
date --rfc-3339=ns
2013-01-30 10:29:43.247318615-06:00

-s, –set=STRING
set time described by STRING

date
Wed Jan 30 20:13:42 CST 2013
date -s "1 year ago"
Mon Jan 30 20:13:47 CST 2012
date
Mon Jan 30 20:13:48 CST 2012
date -s "1 year"
Wed Jan 30 20:13:59 CST 2013
date
Wed Jan 30 20:14:01 CST 2013

-u, –utc, –universal
print or set Coordinated Universal Time

date -u
Thu Jan 31 02:15:46 UTC 2013
date --utc
Thu Jan 31 02:15:53 UTC 2013
date --universal
Thu Jan 31 02:15:57 UTC 2013

–help

Displays help information

–version

date --version
date (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.

That covers all of the command line optional flags. Next we’ll cover all of the FORMAT options

FORMAT controls the output. The only valid option for the second form
specifies Coordinated Universal Time. Interpreted sequences are:

%% a literal %
The % character is used to tell date that we want to use a particular format, however, we may still want to use an actual % sometime in our date. In order to do this just use two %% in a row.

date +'%%'
%

%a locale’s abbreviated weekday name (e.g., Sun)

date +'%a'
Wed

%A locale’s full weekday name (e.g., Sunday)

date +'%A'
Wednesday

%b locale’s abbreviated month name (e.g., Jan)

date +'%b'
Jan

%B locale’s full month name (e.g., January)

date +'%B'
January

%c locale’s date and time (e.g., Thu Mar 3 23:05:25 2005)

date +'%c'
Wed 30 Jan 2013 08:25:05 PM CST

%C century; like %Y, except omit last two digits (e.g., 21)

date +'%C'
20

%d day of month (e.g, 01)

date +'%d'
30

%D date; same as %m/%d/%y

date +'%D'
01/30/13

%e day of month, space padded; same as %_d

date +'%e'
30

%F full date; same as %Y-%m-%d

date +'%F'
2013-01-30

%g last two digits of year of ISO week number (see %G)

date +'%g'
13

%G year of ISO week number (see %V); normally useful only with %V

date +'%G'
2013

%h same as %b

date +'%h'
Jan

%H hour (00..23)

date +'%H'
13

%I hour (01..12)
date +'%I'
12

%j day of year (001..366)

date +'%j'
030

%k hour ( 0..23)

date +'%k'
12

%l hour ( 1..12)

date +'%l'
12

%m month (01..12)

date +'%m'
01

%M minute (00..59)

date +'%M'
02

%n a newline

date +'The year is %Y %nThe Month is %m'
The year is 2013
The Month is 01

%N nanoseconds (000000000..999999999)

date +'%N'
223526735

%p locale’s equivalent of either AM or PM; blank if not known

date +'%p'
PM

%P like %p, but lower case

date +'%P'
pm

%r locale’s 12-hour clock time (e.g., 11:11:04 PM)

date +'%r'
12:04:34 PM

%R 24-hour hour and minute; same as %H:%M

date +'%R'
12:04

%s seconds since 1970-01-01 00:00:00 UTC

date +'%s'
1359569107

%S second (00..60)

date +'%S'
32

%t a tab

date +'Month:%m%tDay:%d'
Month:01 Day:30

%T time; same as %H:%M:%S

date +'%T'
12:07:01

%u day of week (1..7); 1 is Monday

date +'%u'
3

%U week number of year, with Sunday as first day of week (00..53)

date +'%U'
04

%V ISO week number, with Monday as first day of week (01..53)

date +'%V'
05

%w day of week (0..6); 0 is Sunday

date +'%w'
3

%W week number of year, with Monday as first day of week (00..53)

date +'%W'
04

%x locale’s date representation (e.g., 12/31/99)

date +'%x'
01/30/2013

%X locale’s time representation (e.g., 23:13:48)

date +'%X'
12:11:32 PM

%y last two digits of year (00..99)

date +'%y'
13

%Y year

date +'%Y'
2013

%z +hhmm numeric timezone (e.g., -0400)

date +'%z'
-0600

%:z +hh:mm numeric timezone (e.g., -04:00)

date +'%:z'
-06:00

%::z +hh:mm:ss numeric time zone (e.g., -04:00:00)

date +'%::z'
-06:00:00

%:::z numeric time zone with : to necessary precision (e.g., -04,+05:30)

date +'%:::z'
-06

%Z alphabetic time zone abbreviation (e.g., EDT)

date +'%Z'
CST

By default, date pads numeric fields with zeroes. The following optional flags may follow ‘%’:

– (hyphen) do not pad the field

_ (underscore) pad with spaces

0 (zero) pad with zeros

^ use upper case if possible

# use opposite case if possible

After any flags comes an optional field width, as a decimal number; then an optional modifier, which is either E to use the localeâs alternate represen-
tations if available, or O to use the localeâs alternate numeric symbols if available.

DATE STRING
The –date=STRING is a mostly free format human readable date string such as “Sun, 29 Feb 2004 16:21:42 -0800” or “2004-02-29 16:21:42” or even “next
Thursday”. A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers.
An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the
info documentation.

ENVIRONMENT
TZ Specifies the timezone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used.

AUTHOR
Written by David MacKenzie.

REPORTING BUGS
Report date bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
Report date translation bugs to

COPYRIGHT
Copyright © 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
The full documentation for date is maintained as a Texinfo manual. If the info and date programs are properly installed at your site, the command

info coreutils 'date invocation'

should give you access to the complete manual.

Additional Notes
You can, of course, combine these options and formats.

Get a date in the past and change the output format:

date +'%Y-%m-%d' -d "1 day ago"
2013-01-29

This could also be written as

date +'%F' -d "Yesterday"
2013-01-29
Posted in BASH - Tagged BASH, cat, date, example, Format, man, man page, page, shell, time
« BASH> Modify file/directory timestamp
» Usenet> Newznab backfilling

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top