# How to add time to date

**URL:** <https://www.ruby-forum.com/t/how-to-add-time-to-date/188781>\
**Category:** Ruby\
**Created:** [May 18, 2010, 12:48pm UTC](https://www.ruby-forum.com/t/how-to-add-time-to-date/188781 "2010-05-18T12:48:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucky1234](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@lucky1234](https://www.ruby-forum.com/u/lucky1234)\
**Post date:** [May 18, 2010, 12:48pm UTC](https://www.ruby-forum.com/t/how-to-add-time-to-date/188781/1 "2010-05-18T12:48:21Z")

</div>

Hi ,  
Am using javascript calender to select date.am saving same date into  
mydatabase .  
but it’s saving as 2010-18-05 00-00-00  
can amybody help to add time to existed date  
and it should be like 2010-18-05 11:59:00.

can anybody help

---

<div class="post-metadata">

**Author:** ![lucky1234](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d07c76/32.png) [@lucky1234](https://www.ruby-forum.com/u/lucky1234)\
**Post date:** [May 18, 2010, 1:58pm UTC](https://www.ruby-forum.com/t/how-to-add-time-to-date/188781/2 "2010-05-18T13:58:19Z")

</div>

Lucky Nl wrote:

> Hi ,  
> Am using javascript calender to select date.am saving same date into  
> mydatabase .  
> but it’s saving as 2010-18-05 00-00-00  
> can amybody help to add time to existed date  
> and it should be like 2010-18-05 11:59:00.
> 
> can anybody help

Maybe the following will be helpful:

irb(main):011:0\> s=“2010-18-05 00-00-00”  
=\> “2010-18-05 00-00-00”  
irb(main):012:0\> t = Time.now.strftime("%H-%M-%S")  
=\> “19-57-11”  
irb(main):013:0\> s[-8…-1] = Time.now.strftime("%H:%M:%S")  
=\> “19:57:18”  
irb(main):014:0\> s  
=\> “2010-18-05 19:57:18”
