How do you do date math in Linux?
- 1
- Add a Comment
While modern Linux operating systems have more capabilities than you can shake a bag full of sticks at, there are still some tasks that aren’t as easy as you’d like. One of the most common challenges is date math. What’s the date 37 days from today, or 496 days ago? The question I received asked about solving this puzzle within a shell script, but while it’s possible, it’s quite a bit easier to produce a succinct C program to do the work instead:
&nbps; Date Math in a Linux shell script?
It’s always fun to write an actual compiled program after spending so darn much time writing lightweight shell scripts too.
Tags: linux, unix, shell script, c programming language, date math

One Comment
Sea-you
January 20th, 2007
at 2:42pm
Hi, you also can use date for this :)
Example:
date -d’120 seconds ago’
for forward just simply
date -d’120 seconds’
you also can do this with years minutes.
Cheers,
Sea-you