Yesterday’s Date using Shell Script Commands
This page answers questions like these:
- How to get yesterday’s date in a shell script?
- How to get yesterday’s date using bash?
- How do I get yesterday’s date in a shell script?
- How do I get yesterday’s date using a shell command?
Related Links:
Tomorrow's Date using Shell Script Commands
What Day of the Week Was It?
Is this Year a Leap Year? (using Shell Script Commands)
How to get Yesterday’s Date using a Shell Script Command?
date -d yesterday "+%Y-%m-%d"
- Output yesterday’s date as a string in the format “YYYY-MM-DD”.
- The -d option allows you to pass a string which alters the usual output value. Legal strings include (but are not limited too) “yesterday”, “today”, and “tomorrow”.
- The + option allows you to pass a string which alters the usual output format. Legal strings can be composed of normal text and symbols which are expanded by the command:
- %Y = Year as 4 digits.
- %m = Month as 2 digits (01..12).
- %d = Day as 2 digits (01..31).
- %H = Hour as 2 digits (00..23).
- %M = Minute as 2 digits (00..59).
- %S = Second as 2 digits (00..60. Note that 60 can occur for a leap second).
- Some other useful format strings are:
- %A = The full day of the week, e.g. Sunday.
- %a = The abbreviated day of the week, e.g. Sun.
- %B = The full month name, e.g. January.
- %b = The abbreviated month name, e.g. Jan.
How to get the Time One Hour Ago using a Shell Script Command?
date -d "-1 hour" "+%H:%M:%S"
- Output the time exactly 1 hour ago in the format HH:MM:SS where HH is in 24-hour time.
Related Links:
Tomorrow's Date using Shell Script Commands
What Day of the Week Was It?
Is this Year a Leap Year? (using Shell Script Commands)
Home > Linux / Unix > Yesterday’s Date using Shell Script Commands
Tags: yesterday shell script, yesterday bash, yesterday linux, yesterday unix, shell date yesterday, linux date yesterday, date, yesterday’s date, shell script, shell command, linux, unix, solaris, bsd, aix
Copyright © HelpDoco.com
date-yesterday.txt
Linux-Unix/yesterdays-date-using-shell-script-commands.htm
2