You must be using the GNU implementation of
date where that
20200101101010 is interpreted as
2020010110-10-10T00:00:00 local time.
-d is a non-standard option of
date, supported by only a handful of implementations and on those where it's supported, if it is to input a date at all (like in GNU, busybox or ast-open's
-v instead), it's done differently in different implementations.
ast-open and busybox
date allow to specify the input format (busybox with
-D, ast-open with
-p) though not with an offset AFAIK. You could however remove the 5 minutes by converting first to epochtime, remove the 300 seconds and convert back to your format.
There was a proposal in July 2019 to add something similar to GNU
date but it's not been released yet (as of 2020-01-21).
date specifically, you could convert the input (
$aaa) first into a format it recognizes like in @RakeshShewale's
ksh93 syntax approach.
Another option is to use the
zsh shell which has the timestamp parsing and formatting feature built-in and avoid having to rely on non-portable behaviour of
zmodload zsh/datetime || exit
strftime -r -s bbb -- "$format" "$aaa" || exit
strftime -s bbb -- "$format" "$((bbb - 5 * min))"
print -r -- "$bbb"
You can adapt the
$format as required for other formats but note that not all format directives supported by
strftime() (called by
-r to format timestamps) are supported by
strptime() (called by
strftime -r to parse timestamps). Check
man 3 strftime and
man 3 strptime on your system.