Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The -d option format of the Bash command date

Tags:

date

bash

In date's man page:

-d, --date=STRING         display time described by STRING, not 'now'

Sounds like you should input a exact date, but I find date -d "-1 day" works.

I just want a list of the format of -d option of the command date. I googled, but find none.

like image 730
Sayakiss Avatar asked Mar 17 '14 09:03

Sayakiss


2 Answers

From man date:

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.

Then you can get more info and examples typing

info date

Which you can find in Date input formats.

A date is a string, possibly empty, containing many items separated by whitespace. The whitespace may be omitted when no ambiguity arises. The empty string means the beginning of today (i.e., midnight). Order of the items is immaterial. A date string may contain many flavors of items:

  • calendar date items
  • time of day items
  • time zone items
  • combined date and time of day items
  • day of the week items
  • relative items
  • pure numbers.
like image 100
fedorqui 'SO stop harming' Avatar answered Sep 20 '22 23:09

fedorqui 'SO stop harming'


I will try to list just a collection of what you can use with date -d:

  • (last|next) (second|minute|hour|day|month|year)
  • X (seconds|minutes|hours|days|months|years) ago, where X=...,-1,0,1,2,3,...
  • X (second|minute|hour|day|month|year) , where X=...,-1,0,1,2,3,...
  • yesterday, tomorrow
  • @XXXXXXXXX, where XXXXXXXX seconds since epoch
like image 31
trikelef Avatar answered Sep 22 '22 23:09

trikelef