[R] subtract a time period from a date

PIKAL Petr petr.pikal at precheza.cz
Tue Oct 30 13:07:08 CET 2012


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of paladini
> Sent: Tuesday, October 30, 2012 11:26 AM
> To: r-help at r-project.org
> Subject: [R] subtract a time period from a date
> 
> Hello everybody,
> how can I reduce e.g. 30 days from a date?
> When I do  the following  "2011-05-01 CEST" -"2011-04-01 CEST" I get:
> "Time difference of 30 days"
> an thats fine.
> 
> But when I try "2011-05-01 CEST" - 30 I get nonsense.

You subtracted 30 seconds. To subtract 30 days you need to express days in seconds

Sys.time()-(30*24*60*60)
[1] "2012-09-30 14:05:50 CEST"

Regards
Petr

> So how can I subtract some days, month or years from a date?
> 
> 
> 
> thanking you in anticipation
> 
> 
> Claudia Paladini
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list