I would like to be able to parse date fields from a MySQL database in
order
to get the day, year, hour etc. separately. Which library could do that
for
me? I can’t think that I would have to parse those dates myself, right?
Bart
I would like to be able to parse date fields from a MySQL database in
order
to get the day, year, hour etc. separately. Which library could do that
for
me? I can’t think that I would have to parse those dates myself, right?
Bart
Il giorno 08/nov/06, alle ore 16:25, Bart B. ha scritto:
I would like to be able to parse date fields from a MySQL database
in order
to get the day, year, hour etc. separately. Which library could do
that for
me? I can’t think that I would have to parse those dates myself,
right?
Just use Date#day, Date#year, Date#hour and so on.
On Thu, 9 Nov 2006, Bart B. wrote:
I would like to be able to parse date fields from a MySQL database in order
to get the day, year, hour etc. separately. Which library could do that for
me? I can’t think that I would have to parse those dates myself, right?
require ‘time’
parsed_time = Time.parse(mysql_datetime)
If the mysql field has a value that is outside the range for Ruby’s Time
class, you can use DateTime:
require ‘date’
parsed_time = DateTime.parse(mysql_datetime)
Kirk H.
[email protected] wrote:
parsed_time = DateTime.parse(mysql_datetime)
Combined with the methods from Gabriele this works perfectly, thanks!
Bart
On 08/nov/06, at 20:30, Bart B. wrote:
[email protected] wrote:
parsed_time = DateTime.parse(mysql_datetime)
Combined with the methods from Gabriele this works perfectly, thanks!
Oops! Sorry, I thought you were using ActiveRecord, so it was already
parsed
Give it a look, of course you can use it outside Rails, if you need
it: http://rubyonrails.org/api/classes/ActiveRecord/Base.html
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