#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    119
    Rep Power
    91

    Adding x minutes to a DateTime object


    Suppose I have a DateTime object d1, and I want to add x minutes to it to form a second DateTime object d2. How do you do that?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Location
    New Jersey
    Posts
    219
    Rep Power
    137
    You can do something like this. I used the variable names you mentioned in the example.
    Code:
    d2 = d1.advance(:minutes => x)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    119
    Rep Power
    91
    Thanks for the reply. It's in a Rails application, so I also found an approach using since:
    Code:
    x.minutes.since d1

IMN logo majestic logo threadwatch logo seochat tools logo