Simple bash question... I suppose, I'm new.
I have substract date from system time
date_from=`date -d "30 minutes ago"` after, I want format the result in $date_from in 'yyyy-mm-dd'
how can I do that?
date -d "30 minutes ago" +%Y-%m-%d It is very likely, though, that 30 minutes ago it was the same day :)
As you can't guarantee that 30 minutes ago would be the same day, your best solution would be convert the current date/time into seconds from 1970, subtract 30*60 seconds, and then convert this back into a date.
I could do this in a script, not sure how to do it in one line.
Something like:
CURRENT=date +%S CURRENTMINUS30=expr $CURRENT - (30*60) OLD = date -d@`CURRENTMINUS30` That's untested though. I'll have a go at getting the script to work and post it's contents, and perhaps someone else can do it in one line.
date can handle the change in day just fine if necessary.date! I just thought they were unfinished answers. Every day's a school day.