Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get day of the week from a date object?

Tags:

ruby

I have a date object in Rails, which I'd like to format.

I've made it this far:

delivery_time.date.strftime("%w, %d/%m/%Y")

I'd like it to print out 'Wednesday, 04/01/2012'

Is there a quick method to change the '%w' into 'Wednesday'?

like image 737
Finnnn Avatar asked Jan 04 '12 10:01

Finnnn


People also ask

How do you get day from date object?

Javascript date getDay() method returns the day of the week for the specified date according to local time. The value returned by getDay() is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.

How do you determine the first day of the week from a date?

To get the first day of the current week, get the day of the month, subtract the day of the week and add 1 to consider Monday the first day of the week. Copied!

How do I get the day name from date in react native?

Getting the day name from a date: function getDayName(dateStr, locale) { var date = new Date(dateStr); return date. toLocaleDateString(locale, { weekday: 'long' }); } var dateStr = '05/23/2014'; var day = getDayName(dateStr, "nl-NL"); // Gives back 'Vrijdag' which is Dutch for Friday.


1 Answers

Looking at the Ruby docs for strftime

Time.now.strftime("%A, %d/%m/%Y")
=> "Wednesday, 04/01/2012"

The %A character is the full day name.

like image 141
Alex Avatar answered Sep 21 '22 16:09

Alex