Skip to content

Basic date time arithmetics operations

2 messages · Fan, Duncan Murdoch

Fan
#
Hello,

For basic date time arithmetics operations, AFAK, there're 
actually the function difftime() and the (dt + num) operations.

I'm wondering if other basic operations exist, like
add(dt, num, unit) where unit would be "y", "q", "m", etc. 

Also for the function seq.dates (or seq.POSIXt), the 
case for by="months" would be more useful if it takes
the situation of the end of month into account. 
For example,
"2002-01-31 13:00:00 CET" 
"2002-03-03 13:00:00 CET" 
"2002-03-31 13:00:00 CET"

rather than

"2002-01-31 13:00:00 CET" 
"2002-02-28 13:00:00 CET" 
"2002-03-31 13:00:00 CET"

Thanks
--
Fan

************ VITE, C'EST LE MOMENT DE VOUS ABONNER A L'ADSL !!! **********
Du 3 avril au 5 mai, s?rie limit?e ADSL 128K, cliquez vite ici : http://register.tiscali.fr/adsl/ 
Offre promotionnelle soumise ? conditions, r?serv?e aux nouveaux abonn?s ADSL Tiscali.
#
On Sun, 27 Apr 2003 18:14:28 +0200, you wrote:

            
I don't think that's a well-defined request.  What would you want from

 seq(ISOdate(2002,12,30), by="months", length=5)

Should it give February 27, since you asked for the day before the end
of the month?  What should it do in April?

I think the current behaviour is doing what it should doing.  If you
really want the last day of the month in three successive months, then
you should probably get a sequence of first days of months, and then
subtract a day from each.  Wish I could tell you how to do that!
Hopefully someone else will.

By the way, I noticed a typo in the help for difftime() (it was
missing an escape on one of the % signs, so the end of the line
disappeared), and I've committed a fix to R-patched.

Duncan Murdoch