I wrote a shell script that manipulates dates; it gets one or more date strings from the arguments and then outputs a result. Say,
$ datecalc 06/27/2021 01/01/2000 05/10/2005
This script uses the date(1) command for transforming given dates into epoch times, no problem with that. The problem is that it outputs the result in a static format (right now %D). So my main question is: is there a way to get how a date string is formatted?
For instance, I'm looking for a script/function/pipeline/whatever that does the following:
$ getformat "06/27/2021" %m/%d/%Y $ getformat "21/06/27" %y/%m/%d $ getformat "June 27" %B %d
Such that I could do something like the following for the script output:
date -d "$result" +$(getformat "$1")
I already checked dateutils to see if any of its programs could do the job, it doesn't seem like so. I wouldn't mind using one or more of dateutils' programs for achieving this, though.