Search code examples
linuxbashdatetimeexpr

how subtract 10 minutes from a timestamp, not the current time


If I have a variable like 2005, that represents an hour and minute, in this case 08:05pm. How do I subtract 15 minutes from that. If you use expr, you do get something like 1990, which isn't a time. expr works if you are subtracting less than the remaining of the hour, like 2040-15=2025. but that wont work every time.


Solution

  • Using gnu date:

    n='2005'
    date -d "$n 15 min ago" '+%H%M'
    
    1950