# Time stamp display in the view

**URL:** <https://www.ruby-forum.com/t/time-stamp-display-in-the-view/134274>\
**Category:** Rails\
**Created:** [April 9, 2008, 12:54pm UTC](https://www.ruby-forum.com/t/time-stamp-display-in-the-view/134274 "2008-04-09T12:54:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barakathullah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@barakathullah](https://www.ruby-forum.com/u/barakathullah)\
**Post date:** [April 9, 2008, 12:54pm UTC](https://www.ruby-forum.com/t/time-stamp-display-in-the-view/134274/1 "2008-04-09T12:54:20Z")

</div>

hi all,

in my rails application… i am displaying the dtae time… which is  
coming from the database which property is timestamp… so in my view the  
time is displaying as " Wed Apr 09 16:12:52 +0530 2008 "… but that in  
not which i was actually… i need to display only themonth, date and  
time… thats it… just like " Apr 09 16:12 " this… how to get the time  
like this and display… can any one fine\d me a solution for this  
aswell…

thankyou.

with regards,  
barak

---

<div class="post-metadata">

**Author:** ![barakathullah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@barakathullah](https://www.ruby-forum.com/u/barakathullah)\
**Post date:** [April 9, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/time-stamp-display-in-the-view/134274/2 "2008-04-09T13:09:11Z")

</div>

Use: to\_formatted\_s(format = :default)

for example commentDate.to\_formatted\_s(:db)

As per Rails docs:

to\_formatted\_s(format = :default)

Convert to a formatted string - see DATE\_FORMATS for predefined  
formats. You can also add your own formats to the DATE\_FORMATS  
constant and use them with this method.

This method is also aliased as to\_s.  
Examples:

date = Date.new(2007, 11, 10) # =\> Sat, 10 Nov 2007

date.to\_formatted\_s(:db) # =\> “2007-11-10”  
date.to\_s(:db) # =\> “2007-11-10”

date.to\_formatted\_s(:short) # =\> “10 Nov”  
date.to\_formatted\_s(:long) # =\> “November 10, 2007”  
date.to\_formatted\_s(:long\_ordinal) # =\> “November 10th, 2007”  
date.to\_formatted\_s(:rfc822) # =\> “10 Nov 2007”

-Al

On Apr 9, 12:54 pm, Barak I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
