# Converting a number to a date

**URL:** <https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598>\
**Category:** Ruby\
**Created:** [September 22, 2006, 5:13am UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598 "2006-09-22T05:13:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [September 22, 2006, 5:13am UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598/1 "2006-09-22T05:13:23Z")

</div>

My XML request returned a date field as a “string” with the value of  
1158364800000  
Does Ruby have a function to turn this into a date?

Thank you!

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [September 22, 2006, 5:32am UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598/2 "2006-09-22T05:32:20Z")

</div>

Hi,

Hunter W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> My XML request returned a date field as a “string” with the value of  
> 1158364800000  
> Does Ruby have a function to turn this into a date?

% ruby -e ‘p Time.at(“1158364800000”.to\_i / 1000.0).utc’  
Sat, Sep 16 2006 00:00:00 +0000

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [September 22, 2006, 5:53am UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598/3 "2006-09-22T05:53:19Z")

</div>

WATANABE Hirofumi wrote:

> Hi,
> 
> Hunter W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> > My XML request returned a date field as a “string” with the value of  
> > 1158364800000  
> > Does Ruby have a function to turn this into a date?
> 
> % ruby -e ‘p Time.at(“1158364800000”.to\_i / 1000.0).utc’  
> Sat, Sep 16 2006 00:00:00 +0000

This helps a lot. Thank you!

Now we’ll see if I can do some math with it.

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [September 22, 2006, 4:37pm UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598/4 "2006-09-22T16:37:33Z")

</div>

On Friday, September 22, 2006, at 12:13 PM, Hunter W. wrote:

> My XML request returned a date field as a “string” with the value of  
> 1158364800000  
> Does Ruby have a function to turn this into a date?
> 
> Thank you!
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

You can, if you have any idea how that date is being encoded. It  
doesn’t seem like a timestamp, and it’s not the format a Date or  
DateTime object uses.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [September 22, 2006, 4:43pm UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598/5 "2006-09-22T16:43:22Z")

</div>

Kevin O. wrote:

> On Friday, September 22, 2006, at 12:13 PM, Hunter W. wrote:
> 
> > My XML request returned a date field as a “string” with the value of  
> > 1158364800000  
> > Does Ruby have a function to turn this into a date?
> > 
> > Thank you!
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> You can, if you have any idea how that date is being encoded. It  
> doesn’t seem like a timestamp, and it’s not the format a Date or  
> DateTime object uses.
> 
> \_Kevin  
> [www.sciwerks.com](http://www.sciwerks.com)

What format do I need for the Date or DateTime object?

---

<div class="post-metadata">

**Author:** ![siguva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@siguva](https://www.ruby-forum.com/u/siguva)\
**Post date:** [September 22, 2006, 5:29pm UTC](https://www.ruby-forum.com/t/converting-a-number-to-a-date/69598/6 "2006-09-22T17:29:40Z")

</div>

On Friday, September 22, 2006, at 11:43 PM, Hunter W. wrote:

> > >
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

There are a number of ways to parse dates and times. The most basic  
would be to use a unix timestamp (integer) and then just use the  
Time.at(value) function.

you can also use ParseDate, or DateTime.parse, or the Chronic gem.

I guess my real question is:  
What does “1158364800000” represent? It is unlike any time format I’ve  
seen.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)
