2

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.

1 Answers1

4

Using gnu date:

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

1950
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    It did. This was my first question to this forum, so I didnt see how to reply until just now. Thanks alot. – Randy Adams Mar 21 '16 at 21:33
  • It does what I asked, but I decided that what I was asking for is only half what what I need. i am stuck on the second part of the same problem. Thanks again. – Randy Adams Mar 21 '16 at 21:48
  • Feel free to post a new question if are stuck on it for long time – anubhava Mar 21 '16 at 21:50