Anyone know how to take a date or time prior to 1970 and convert it into
negative seconds or milliseconds?
I know there is time.to_i, but a Time object can’t be prior to 1970 or
else it will throw an error.
Anyone know how to take a date or time prior to 1970 and convert it into
negative seconds or milliseconds?
I know there is time.to_i, but a Time object can’t be prior to 1970 or
else it will throw an error.
On Oct 31, 11:52 am, Aryk G. [email protected]
wrote:
Anyone know how to take a date or time prior to 1970 and convert it into
negative seconds or milliseconds?I know there is time.to_i, but a Time object can’t be prior to 1970 or
else it will throw an error.Posted viahttp://www.ruby-forum.com/.
ActiveSupport Time#to_date
http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html#M000327
you should be aware that SQL server and Oracle have had gotchas
concerning Date and Datetime objects, tho i don’t recall specifics
now.
On Oct 31, 2:18 pm, gene tani [email protected] wrote:
ActiveSupport Time#to_datehttp://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/…
you should be aware that SQL server and Oracle have had gotchas
concerning Date and Datetime objects, tho i don’t recall specifics
now.
BTW: Oracle and SQLserver:
http://dev.rubyonrails.org/ticket/3430
http://blog.rayapps.com/2007/08/27/how-to-explicitly-set-oracle-date-column-as-ruby-date-attribute/
Aryk G. [email protected] wrote:
What im trying to do is a take a Date object occurring before 1970 and
convert it into negative milliseconds/seconds.
This will do seconds:
irb(main):005:0> require “date”
=> true
irb(main):006:0> d = Date.parse(“1950-01-01”)
=> #<Date: 4866565/2,0,2299161>
irb(main):007:0> d.strftime(“%s”)
=> “-631152000”
irb(main):008:0> d.strftime(“%s”).to_i
=> -631152000
Cheers,
Tyler
Right, Im aware of the to_date function, but that returns a date object.
What im trying to do is a take a Date object occurring before 1970 and
convert it into negative milliseconds/seconds.
so I want the resulting value to be a negative integer. So what you are
showing me doesnt work unless you can craft a simple proof of concept
using those functions.
Thanks Tyler, you’re awesome.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs