# Month and day

**URL:** <https://www.ruby-forum.com/t/month-and-day/109660>\
**Category:** Ruby\
**Created:** [July 17, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/month-and-day/109660 "2007-07-17T17:27:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 17, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/month-and-day/109660/1 "2007-07-17T17:27:38Z")

</div>

Assuming that to day it January 1 2007 when the  
following code is and the response is 1. Is there a  
way to get back 01? I’m also looking to get 01 for  
the day. It looks like %m and %d is what I’m looking  
for but I don’t know how to implement the formatting.

t = Time.now  
puts t.mon  
=\> 1

Jeff

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 17, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/month-and-day/109660/2 "2007-07-17T17:33:38Z")

</div>

Never mind I to got it. It most be putting it in  
writing jogs the brain.

t = Time.now

puts t.strftime(“%m%d”)

Jeff  
— Jeffrey B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> 1
> 
> Jeff

* * *

> Be a better Globetrotter. Get better travel answers  
> from someone who knows. Yahoo! Answers - Check it  
> out.

> **[Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos](https://www.yahoo.com/)**
>
> Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 17, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/month-and-day/109660/3 "2007-07-17T17:35:39Z")

</div>

On 7/17/07, Jeffrey B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Assuming that to day it January 1 2007 when the  
> following code is and the response is 1. Is there a  
> way to get back 01? I’m also looking to get 01 for  
> the day. It looks like %m and %d is what I’m looking  
> for but I don’t know how to implement the formatting.
> 
> t = Time.now  
> puts t.mon  
> =\> 1

irb\> ‘%02d’ % Time.now.mon  
07  
=\> nil

Todd
