# Formatting a unix timestamp

**URL:** <https://www.ruby-forum.com/t/formatting-a-unix-timestamp/115324>\
**Category:** Rails\
**Created:** [September 23, 2007, 10:47pm UTC](https://www.ruby-forum.com/t/formatting-a-unix-timestamp/115324 "2007-09-23T22:47:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [September 23, 2007, 10:47pm UTC](https://www.ruby-forum.com/t/formatting-a-unix-timestamp/115324/1 "2007-09-23T22:47:12Z")

</div>

I have a database with unix timestamps in it (saved as varchar)…

Right now I’m using the following to format it (item table, created\_at  
field)…:

Time.at(item.created\_at.to\_i).strftime("%Y-%m-%d %H:%M:%S")

I was wondering if it’s the most effective way to do it? Or if there is  
a quicker way?

---

<div class="post-metadata">

**Author:** ![silvertab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@silvertab](https://www.ruby-forum.com/u/silvertab)\
**Post date:** [September 23, 2007, 10:57pm UTC](https://www.ruby-forum.com/t/formatting-a-unix-timestamp/115324/2 "2007-09-23T22:57:32Z")

</div>

On 23 Sep 2007, at 22:47, Jean-nicolas Jolivet wrote:

> a quicker way?  
> item.create\_at.to\_formatted\_s(:db)

Same can be done with dates.

Best regards

Peter De Berdt
