calculate with date

calculate with date

Post by Mathias Pippe » Fri, 11 Nov 2005 20:05:41



Hi,

i am looking for a way to calculate with dates.
I need something that i can say go 4 days in the past
and give me the date.

For example:

go from 02/3/1980 four days back and give me the date.

I have done experiments with 'date' but i do not know if
it is capable of doing what i want.

I thought about converting the date in
seconds since `00:00:00 1970-01-01 UTC' and then just
adding the amounts of seconds i need. But i did not found
a tool for reversion and the seconds extension is a GNU
feature.

Thanks

 
 
 

calculate with date

Post by John » Fri, 11 Nov 2005 20:26:06



> Hi,

> i am looking for a way to calculate with dates.
> I need something that i can say go 4 days in the past
> and give me the date.

> For example:

> go from 02/3/1980 four days back and give me the date.

> I have done experiments with 'date' but i do not know if
> it is capable of doing what i want.

> I thought about converting the date in
> seconds since `00:00:00 1970-01-01 UTC' and then just
> adding the amounts of seconds i need. But i did not found
> a tool for reversion and the seconds extension is a GNU
> feature.

Either use Gnu date or rush out and buy regular poster
Chris FA Johnson's book.
http://www.apress.com/book/bookDisplay.html?bID=419

There is a sample chapter online which, by a happy coincidence,
deals with the thorny problem of date arithmetic.
http://www.apress.com/ApressCorporate/supplement/1/419/1590594711-272...

--
John.

 
 
 

calculate with date

Post by Ed Morto » Fri, 11 Nov 2005 23:23:42



> Hi,

> i am looking for a way to calculate with dates.
> I need something that i can say go 4 days in the past
> and give me the date.

> For example:

> go from 02/3/1980 four days back and give me the date.

> I have done experiments with 'date' but i do not know if
> it is capable of doing what i want.

> I thought about converting the date in
> seconds since `00:00:00 1970-01-01 UTC' and then just
> adding the amounts of seconds i need. But i did not found
> a tool for reversion and the seconds extension is a GNU
> feature.

> Thanks

See question 6 in the FAQ (http://home.comcast.net/~j.p.h/cus-faq.html#6).

        Ed.

 
 
 

calculate with date

Post by Harr » Sat, 12 Nov 2005 07:35:32


Quote:Mathias Pippel wrote...

>Hi,

>i am looking for a way to calculate with dates.
>I need something that i can say go 4 days in the past
>and give me the date.

>For example:

>go from 02/3/1980 four days back and give me the date.

if you don't mind compiling a utility ...

c:\> mktime -D 1980-02-03 -d -4 -F '%%Y-%%m-%%d'
1980-01-30

Google for mktime-2.3.tar.gz.

 
 
 

calculate with date

Post by William Jame » Sat, 12 Nov 2005 11:03:43



> Hi,

> i am looking for a way to calculate with dates.
> I need something that i can say go 4 days in the past
> and give me the date.

> For example:

> go from 02/3/1980 four days back and give me the date.

> I have done experiments with 'date' but i do not know if
> it is capable of doing what i want.

> I thought about converting the date in
> seconds since `00:00:00 1970-01-01 UTC' and then just
> adding the amounts of seconds i need. But i did not found
> a tool for reversion and the seconds extension is a GNU
> feature.

> Thanks

ruby -r date -e'puts (Date.new(1980,2,3)-4)'

Quote:>>>--->   1980-01-30

5.times { |n|
  change = 10**n
  d = Date.new(1980,2,3) - change
  puts "%6d -> %02d/%02d/%d" % [change,d.mon,d.day,d.year]

Quote:}

     1 -> 02/02/1980
    10 -> 01/24/1980
   100 -> 10/26/1979
  1000 -> 05/09/1977
 10000 -> 09/17/1952
 
 
 

calculate with date

Post by Mathias Pippe » Sat, 12 Nov 2005 21:34:57


<snip>

Quote:

> 5.times { |n|
>   change = 10**n
>   d = Date.new(1980,2,3) - change
>   puts "%6d -> %02d/%02d/%d" % [change,d.mon,d.day,d.year]
> }

>      1 -> 02/02/1980
>     10 -> 01/24/1980
>    100 -> 10/26/1979
>   1000 -> 05/09/1977
>  10000 -> 09/17/1952

Thanks for all the help, and yes i should have read the faq
carefully first ;)

actually i am the gnu date util when i want to a few days back with:

date -d "7 days ago" +[format options]