Ruby on Rails Saturday, September 21, 2013

But not all months are 2592000 seconds long.....some are shorter and some are longer....
If you have a Date of 1 Jan and add 1.month to it you will get 1 Feb which is 31 days later.  If you have 1 Feb and you add 1.month you will get 1 Mar which is 28 or 29 days later.

You could just store the value as x so you could do Time.now + x.month

Norm

On 09/20/2013 01:47 AM, Raj Kumar wrote:
I don't think this is good idea. 1.month.to_i will return in seconds as 2592000. you can store this and while fetching you can use it as it is
Time.now + 2592000

On Friday, 20 September 2013 03:30:16 UTC-4, Fai Wong wrote:
If I store 1.month as a string in the database, how do I convert "1.month" into 1.month?

This way I can use the "1.month" value stored in database to perform the following calculation.

Time.now + 1.month 
--

No comments:

Post a Comment