DEV Community

AakritiGoyal12458
AakritiGoyal12458

Posted on

Date Command in Linux

Date command in Linux

  1. date command is used to display both date and time in Linux .
  2. you can format date and time by using this command

In Terminal

  1. date
  2. man date : this command will open date manual

using some command

  1. date -d "STRING"

date -d "now"
date -d "today"
date -d "yesterday"
date -d "tomorrow"
date -d "1 hour ago" // no.of hour and then add ago keyword
date -d "1 hour " //to check future timming do not add ago keyword.
date -d "2 years 3 months and 1 day"
date -d "2 years 3 months and 1 day ago "

Alt Text

now, lets set the time

  1. date -s "STRING"

  2. date utc --universal time

date-u

  1. trying various formats with date command

syntax== date +%FORMAT

tip--you can simply type man date to see commands no need to learn them

lets go through some examples
1.date +%r //to see only time
2.date +%D //to see only date
3.date +%d%m%y //to see date in format you want
4.date +%d/%m/%y //use "/" for cleanliness
5.date +%d/%m/%Y //"Y" to display year in 4 digit
6.date +%d/%b/%Y //b used to display month in 3 leter eg. September as Sep
7.date +"%d %b %Y" //to use spaces you have to make sure to enclose between double inverted quotes.
8.date +"%a %d %b %Y" //%a for days in 3 letters eg. monday as mon
9.date +"%A %d % b %Y" //%A for full day name eg. monday as MONDAY only
10.date +"%A %-d %-m %Y" //using "-" removes 0 from the single digit number .
11.date +"%A %-d %-m %H %M %S" // hours , min and seconds
12.date +"%A %-d %-m %I %M %S" //12 hour format
13.date +"%A %-d %-m %I %M %S %p"// to display time in AM

Alt Text

similarly you can try more commands .

Top comments (0)