Hi, I''ve got a TimeStamp field in MySql and want to use the hour and minutes in the value. for example: StartTime = Schedule.find(action2.ScheduleID).DateTimeStart.to_s That returns "Mon Feb 20 08:00:00 Romance Standard Time 2006" How do I get 08:00 returned ?? Thanks ! Steven. -- Posted via http://www.ruby-forum.com/.
Steven De Ryck wrote:> Hi, > > I''ve got a TimeStamp field in MySql and want to use the hour and minutes > in the value. > > for example: > > StartTime = Schedule.find(action2.ScheduleID).DateTimeStart.to_s > > That returns "Mon Feb 20 08:00:00 Romance Standard Time 2006" > > How do I get 08:00 returned ?? > > Thanks ! > > Steven.try "date.to_formatted_s format_string" it uses the same syntax as strftime documented here: http://www.rubycentral.com/ref/ref_c_time.html#strftime I would write what you need like this: start_time = Schedule.find(action2.schedule_id).date_time_start.to_formatted_s("%H:%M") -- Posted via http://www.ruby-forum.com/.
I allready tried that: Schedule.find(action2.ScheduleID).DateTimeStart.to_formatted_s("%H:%M") Still returns something like "Fri Feb 24 20:00:00 Romance Standard Time 2006" .. Steven. Alex Wayne wrote:> Steven De Ryck wrote: >> Hi, >> >> I''ve got a TimeStamp field in MySql and want to use the hour and minutes >> in the value. >> >> for example: >> >> StartTime = Schedule.find(action2.ScheduleID).DateTimeStart.to_s >> >> That returns "Mon Feb 20 08:00:00 Romance Standard Time 2006" >> >> How do I get 08:00 returned ?? >> >> Thanks ! >> >> Steven. > > try "date.to_formatted_s format_string" > > it uses the same syntax as strftime documented here: > http://www.rubycentral.com/ref/ref_c_time.html#strftime > > I would write what you need like this: > > start_time = > Schedule.find(action2.schedule_id).date_time_start.to_formatted_s("%H:%M")-- Posted via http://www.ruby-forum.com/.