Hi the below code is failing i am trying to generate do the following:
2014-10-22 11:26:00 (Substract 24 hrs)
should produce
2014-10-21 11:26:00
I need the same formatting below because that gets inputted into code for an applcication report and it must match the applicaiton accepted format.
hourt="$d $h:$m:00"
hour2="$d $(printf '%02d:%02d:00' $((${h#0} - 12)) $m)"
2014-10-22 11:38:00
2014-10-22 -13:38:00
How do i subtract 1 day? without the negative being produced.
Thanks,
Sam
What is your system? Do you have GNU date? Date math isn't trivial unfortunately, with leap years and varying lengths of months.
cjcox
3
If GNU date, consider:
date -d '2014-10-22 11:26:00 CDT - 1 day'
If old Unix date, you can manipulate UTC/GMT 0 withing 24 hours.... so you can do things like:
TZ=UTC24 date
The latter might not help... all depends on what you can or cannot do on your system.
rhel5 yes ive got gnu date.
im messing with the below but cant get right format...
how do I add hrs at the into it???
date --date "-1 days" +'%Y-%m-%d'
2014-10-21 11:38:00
like above
---------- Post updated at 12:29 PM ---------- Previous update was at 12:26 PM ----------
date --date "-1 days" +'%Y-%m-%d %H:%M:%S'
Got it 
---------- Post updated at 12:32 PM ---------- Previous update was at 12:29 PM ----------
thanks for reminding me corona! I always forget about GNU date :S
Aia
5
That format combination is common enough that there's even a shortcut for it:
date --date "-1 days" +'%F %T'