Skip to content

adding 1 month to a date

3 messages · bogdan romocea, Brian Ripley, Marc Schwartz

#
Simple addition and subtraction works as well:
  as.Date("1995/12/01",format="%Y/%m/%d") + 30
If you have datetime values you can use
  strptime("1995-12-01 08:00:00",format="%Y-%m-%d %H:%M:%S") + 30*24*3600
where 30*24*3600 = 30 days expressed in seconds.
#
On Wed, 12 Oct 2005, bogdan romocea wrote:

            
Sorry, not in general, as a month is not generally of 30 days (including 
in your example).

seq.Date is a good way to do this.

  
    
#
Thanks to Prof. Ripley for pointing this out.

One of the approaches that I had considered here was to set up a vector
of the number of days in each month (adjusting of course for leap
years), and use "day arithmetic" to add/subtract the appropriate number
of days.

However, it was easier to use seq.Date() and to further consider putting
a wrapper around it to make it yet even easier to use.

Marc
On Wed, 2005-10-12 at 13:23 +0100, Prof Brian Ripley wrote: