Creating a date

Basic types / Date and time

#the time zone of the example; without it the local one is used
export TZ=UTC

year=1945
month=5
day=9

#printf builds the text of the date in the ISO form
printf -v isoDate '%04d-%02d-%02d' "$year" "$month" "$day"
#isoDate is "1945-05-09"

#date -d makes a date of it and adds the day of the week
victoryDate=$(date -d "$isoDate" '+%Y-%m-%d, %A')
#victoryDate is "1945-05-09, Wednesday"

#+%s gives seconds since 1970, a negative number before it
seconds=$(date -d "$isoDate" +%s)
#seconds is -777859200
(( seconds < 0 )) && beforeEpoch=true || beforeEpoch=false
#beforeEpoch is true

echo "isoDate is $isoDate"
echo "victoryDate is $victoryDate"
echo "seconds is $seconds"
echo "beforeEpoch is $beforeEpoch"