Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get yesterday and day before yesterday in linux?

Tags:

linux

shell

unix

I want to get sysdate -1 and sysdate -2 in variable and echo it. I am using below query which gives todays date as output.

#! /bin/bash tm=$(date +%Y%d%m) echo $tm 

How to get yesterday and day before yesterdays date?

like image 754
user3164140 Avatar asked Feb 26 '14 13:02

user3164140


People also ask

How can I get yesterday's date?

How do you get yesterdays' date using JavaScript? We use the setDate() method on yesterday , passing as parameter the current day minus one. Even if it's day 1 of the month, JavaScript is logical enough and it will point to the last day of the previous month.


1 Answers

Here is another one way,

For yesterday,

date -d '-1 day' '+%Y%d%m' 

For day before yesterday,

date -d '-2 day' '+%Y%d%m' 
like image 116
sat Avatar answered Oct 12 '22 01:10

sat