Search This Blog

Linux dates - yesterday, today and tomorrow

You might be familiar with the UNIX environment. You might have started from echo command and reached till the advanced grep command. Even then sometime you will face the situation that makes you to think that you have not learnt the complete UNIX. To solve your problem here we will learn a bit of UNIX by knowing how to use get the today's, yesterday's and tomorrow's date and many more.

To get the today's date

date +"%d-%m-%y"
It will display the date in dd-mm-yy format. Displays only the last two digits of the year. If you replace yy with Y you will get the complete year in 4 digits. date +"%d-%m-%Y If you want the yesterdays date you need to use -d switch with date as shown below

date -d"-1 day" +"%d-%m-%y"

In this case, the string -1 day specifies one day before the current day.

Similarly to get the tomorrow's date you need to specify the string as +1 day date -d"+1 day" +"%d-%m-%y"

Sometimes you need to get the date 2 days before or 2 days later than make use of -/+ n day properly to get the required date where n stands for number.