# TimeStamp conversion

**URL:** <https://www.ruby-forum.com/t/timestamp-conversion/58633>\
**Category:** Rails\
**Created:** [April 24, 2006, 10:43am UTC](https://www.ruby-forum.com/t/timestamp-conversion/58633 "2006-04-24T10:43:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 24, 2006, 10:43am UTC](https://www.ruby-forum.com/t/timestamp-conversion/58633/1 "2006-04-24T10:43:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 24, 2006, 11:02am UTC](https://www.ruby-forum.com/t/timestamp-conversion/58633/2 "2006-04-24T11:02:46Z")

</div>

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](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”)

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 24, 2006, 11:13am UTC](https://www.ruby-forum.com/t/timestamp-conversion/58633/3 "2006-04-24T11:13:35Z")

</div>

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 W. 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](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”)

---

<div class="post-metadata">

**Author:** ![S-redyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@S-redyck](https://www.ruby-forum.com/u/S-redyck)\
**Post date:** [April 24, 2006, 11:36am UTC](https://www.ruby-forum.com/t/timestamp-conversion/58633/4 "2006-04-24T11:36:45Z")

</div>

Nevermind, I solved it with:

" Schedule.find(action2.ScheduleID).DateTimeStart.strftime("%H:%M").to\_s  
"
