# How to know the current weekday?

**URL:** <https://www.ruby-forum.com/t/how-to-know-the-current-weekday/169555>\
**Category:** Rails\
**Created:** [June 5, 2009, 9:17am UTC](https://www.ruby-forum.com/t/how-to-know-the-current-weekday/169555 "2009-06-05T09:17:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnxgn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jnxgn](https://www.ruby-forum.com/u/jnxgn)\
**Post date:** [June 5, 2009, 9:17am UTC](https://www.ruby-forum.com/t/how-to-know-the-current-weekday/169555/1 "2009-06-05T09:17:28Z")

</div>

I failed to find what is the weekday by following codes:

timetoday = Time.now

if timetoday =~ /Fri/  
puts “Friday”  
end

Please help to analysis what is the probleme$B!#e(B  
puts timetoday  
It will display: Fri Jun \*\*\*\* 2009  
but it is not true for: timetoday =~ /Fri/

---

<div class="post-metadata">

**Author:** ![jnxgn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jnxgn](https://www.ruby-forum.com/u/jnxgn)\
**Post date:** [June 5, 2009, 9:22am UTC](https://www.ruby-forum.com/t/how-to-know-the-current-weekday/169555/2 "2009-06-05T09:22:46Z")

</div>

On Jun 5, 12:01 am, jnxgn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It will display: Fri Jun \*\*\*\* 2009  
> but it is not true for: timetoday =~ /Fri/

Instances of Time do not implement a =~ which does that. When you run  
Time.now at the console it gets converted to a string (and that string  
has a =~ method which behaves as you expect). Converting your time to  
a string would sort of work but you really shouldn’t do that - just  
examine the value of timetoday.wday

Fred

---

<div class="post-metadata">

**Author:** ![jnxgn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jnxgn](https://www.ruby-forum.com/u/jnxgn)\
**Post date:** [June 5, 2009, 9:28am UTC](https://www.ruby-forum.com/t/how-to-know-the-current-weekday/169555/3 "2009-06-05T09:28:03Z")

</div>

From what Fred mentioned, you can also use timetoday.wday  
to get the corresponding day name from the Date::DAYNAMES  
Array constant.

Try this and see what you get:

puts Date::DAYNAMES[timetoday.wday]

Franz

---

<div class="post-metadata">

**Author:** ![jnxgn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@jnxgn](https://www.ruby-forum.com/u/jnxgn)\
**Post date:** [June 5, 2009, 10:54am UTC](https://www.ruby-forum.com/t/how-to-know-the-current-weekday/169555/4 "2009-06-05T10:54:02Z")

</div>

Or if you want abbreviated version you can use

Date::ABBR\_DAYNAMES[Time.now.wday]

BoÅ¡ko
