How to generate datetime string?

Hi. I'm hoping there is a simple method where I'm able to generate a datetime string that looks like this (yyyymmddhhmm):

201106280830

The tricky part would be that I need this string to be today's datetime minus 1 year.

Is there anyway to do this?

date +"expr "%Y%m%d%H%M" - 100000000" | sh
1 Like

if you are using gnu date, then try the below

$ date +%Y%m%d%H%M
201106282047

$ date -d "1 year ago" +%Y%m%d%H%M
201006282047
1 Like

jayan_jay you rock. Thank you so much!