I want to convert a date into a timestamp.
My input looks something like:
Mon Sep 30 17:37:39 2019
And I want to take that timestamp and check how many days that have passed since today.
What I tried:
data = "$(date --date "$(echo "$info" | grep "Date added: *" | sed 's/Date added\:\s//i' | awk '{$1=$1};1')" '+%H')"
final = $(expr $(date '+%H') - $data)
However this will in some cases print out values such as -9, -3, -12 etc and for todays date it currently print out "08". Any ideas how to solve this?
Something that is worth mentioning is that I dont really care about exact hours if that complicates things, I am more interesting in how many days that have passed.
EDIT
Current solution (does not handle hours which is a bummer). I extract the Day, Month and Year and organise it into YYYY-MM-DD and thereafter convert it to a timestamp. This solution do not handle hours which I do want in the end.
$(( ($(expr $(date '+%s')) - $(date -d "$(printf '%s\n' "$date_added" | awk '{
printf "%04d-%02d-%02d\n", $5, \
(index("JanFebMarAprMayJunJulAugSepOctNovDec",$2)+2)/3,$3}')" +"%s")) / 3600 ))