How to get yesterday's date in a particular format?
问题 I need to set Today and yesterday's date in a variable in a fixed format YYYYMMDD . For today date, when i did SET TODAY=%date:~10,4%%date:~4,2%%date:~7,2% it worked and displayed '20190426'. But how to set yesterday's date so I get it in the format - 20190425 ? 回答1: Update The original unix and linux tags were later changed to cmd and batch-file, which this Linux / Bash / sh solution won't apply to. To get yesterday's date: $ date +%Y%m%d --date yesterday 20190425 To get it into a var: $ var