Offline method required to find out number of days since a certain date!
Hi.
What offline method is there of finding out days since a certain date. Example: How would someone find the number of days from 1-Jan-2003 to 7-Dec-2010? Could someone write a script that takes in the 2 dates and output the number of days? Thanks. |
What have you tried so far? Basically you need to convert the two dates in seconds since the system reference time (epoch for unix shells), subtract them and divide the result by 86400. If you're interested in the fractional part you can use either bc or awk, since the shell doesn't do floating point arithmetic.
|
Code:
[cpt_scarlet@spectrum:~] $ ((datediff=(( `date -u -d "2010-07-12" +%s` - `date -u -d "2003-01-01" +%s`)))) |
Or it might be
Code:
[cpt_scarlet@spectrum:~] $ ((datediff=(( `date -u -d "2010-12-07" +%s` - `date -u -d "2003-01-01" +%s`)))) |
Quote:
|
You can either write a script or a function passing the two dates as arguments. Example, if you define a function:
Code:
function datediff () { Code:
$ datediff 1-Jan-2003 7-Dec-2010 |
All times are GMT -5. The time now is 04:38 PM. |