sonam_sharma sonam_sharma - 9 months ago 42
Linux Question

How to set a variable to current date and date-1 in linux?

I want to set the variable

to the current date, and
to yesterday's date, both in the format

I am doing this:

d=`date +%y%m%d%H%M%S`
echo $d

Answer Source

You can try:

d=$(date +%Y-%m-%d)
echo "$d"

EDIT: Changed y to Y for 4 digit date as per QuantumFool's comment.