DEV Community


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


  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 +%r //to see only time +%D //to see only date +%d%m%y //to see date in format you want +%d/%m/%y //use "/" for cleanliness +%d/%m/%Y //"Y" to display year in 4 digit +%d/%b/%Y //b used to display month in 3 leter eg. September as Sep +"%d %b %Y" //to use spaces you have to make sure to enclose between double inverted quotes. +"%a %d %b %Y" //%a for days in 3 letters eg. monday as mon +"%A %d % b %Y" //%A for full day name eg. monday as MONDAY only +"%A %-d %-m %Y" //using "-" removes 0 from the single digit number . +"%A %-d %-m %H %M %S" // hours , min and seconds +"%A %-d %-m %I %M %S" //12 hour format +"%A %-d %-m %I %M %S %p"// to display time in AM

Alt Text

similarly you can try more commands .

Discussion (0)