week number of the year, kinda

Related searches

Preferably in ruby, but the logic would be good enough...

I need the week number of the year given that the week is non-standard. So, say you define a week as Saturday -> Friday. Then, given a date, which week number (1-52) is it?

strftime has %U:

> Time.now.strftime('%U')
> => "28"

...but that of course assumes a standard Sunday -> Saturday week.

Use %W instead of %U, it uses Monday as the first day of the week.


What's the Current Week Number?, The highest week number in a year is either 52 or 53. 2020 has 53 weeks. ISO 8601 is not the only week numbering system in the world, other systems use weeks� Year 2014 starts with Wed, but our algorithm puts Jan 1 in week 0 but it should be week 1 (%U puts Jan 1 in week 1 if it's Sunday). Year 2007 (and other years that start on Mon or Tue) will cause the days before the first Wed to be in week -1 but they should be week 0. The more days of the week you're adjusting, the more edge cases you'll have

class Date
  def sweek
    date = self + 1

# Today is Sunday, 17 July
#=> 28
#=> 29

Week Numbers for 2020, There are 53 weeks in 2020. All weeks are starting on Monday and ending on Sunday. Please note that there are multiple systems for week numbering, this is the� Calculate the week number of any date and find the beginning and end date of a specific week of any year.

Maybe can do like this;

def week_dates( week_num )
    year = Time.now.year
    week_start = Date.commercial( year, week_num, 1 )
    week_end = Date.commercial( year, week_num, 7 )
    week_start.strftime( "%m/%d/%y" ) + ' - ' + week_end.strftime( 
"%m/%d/%y" )

How to use the 'date' command to display week number of the year , There are actually 3 kind of week number in year for the date command : %U week number of year, with Sunday as first day of week (00..53); %W week number of� Week 37 is from Monday, September 7, 2020 until (and including) Sunday, September 13, 2020. Week number according to the ISO-8601 standard, weeks starting on Monday. The first week of the year is the week that contains that year's first Thursday (='First 4-day week'). ISO representation: 2020-W37. The highest week number in a year is either 52

Week number in MySQL, MySQL has two functions that return the ISO 8601 calendar week number: The first function returns the ISO 8601 week for a given date, whereas the second one the YEARWEEK function which returns the year and week number for a date It might really be a good information that you have shared this kind of thing� View the week numbers of 2020 In the list below you can find every week number of this year. Are you looking for a number for another year? Take a look at one of the calendar pages, start your search via this year's 2020 calendar.

If you want a ISO week number use %V according strftime documentation


require 'date'

puts DateTime.parse('2018-12-30 23:59:59').strftime('%G-%V')
puts DateTime.parse('2018-12-31 00:00:00').strftime('%G-%V')



Note that it was used %G for year and not %Y.

Calculating ISO 8601 Week Number for Dates in Power Automate , If I was using Excel, I could find out the week number for a date using the I'm not the kind of person to back down from a challenge though, so I The first ISO week of a year is the first week that contains the first Thursday of� What week of the year is it? This single serving app calculates the week of the year and day of the year for the current day and for any day which you specify. Select a date from the calendar to see this in action. Please note that this site uses the ISO week date system. This is used primarily for financial and government timekeeping.

Week 37 begins on Monday, September 7, 2020. Check the current week number and convert between dates and week numbers on Weeknumber.net.

specifies the number-of-the-week within the year. Sunday is considered the first day of the week. The number-of-the-week value is represented as a decimal number in the range 0-53. Week 53 has no special meaning.

The pattern of the seventh day of rest in the week for the weekly Sabbath continues with the seven yearly Sabbath days in a year. This pattern of seven is also the number of weeks between the first yearly Sabbath of Passover and Pentecost. The pattern continues with the seventh year, which is a Sabbath year to the land.

  • maybe use this standard and then calculate your own offset based on todays day of week...
  • Sunday -> Saturday is only American standard. International standard is Monday -> Sunday.
  • But it's zero indexed, as opposed to Date.today.cweek form @fl00r's answer.
  • nice, but +0 for monkey patching a core class, btw strangely Time.new.strftime('%W') != Time.new.to_date.cweek
  • @akostadinov: You probably got this long ago now, but for posterity, Time.new.strftime('%W') returns a String while Time.new.to_date.cweek returns an Integer, so they're not expected to be equal.
  • Looking for the week number of a given date.