sonam_sharma sonam_sharma - 1 year ago 77
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download