kensaii kensaii - 1 year ago 80
Bash Question

Calculate 15 minutes ago in shell

I have a time-stamp like 7:00:00, which means 7am.

I would like to write a short command that returns 06:45:00, or simply 06:45, preferably using date command so that I can avoid long shell script. Do you have any elegant solution?

Answer Source

With GNU date, use 7:00:00 AM - 15 minutes as d (--date) string :

% date -d '7:00:00 AM - 15 minutes' '+%H:%M'

+%H:%M sets the output format as HH:MM.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download