Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8583579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:34:17+00:00 2026-06-11T21:34:17+00:00

Using Ruby how can you determine if the coming Sunday is the first, second

  • 0

Using Ruby how can you determine if the coming Sunday is the first, second or third Sunday of the month?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:34:18+00:00Added an answer on June 11, 2026 at 9:34 pm

    @ElYusubov – is close, but not quite right.

    As a starting point, the division must be by seven (number of days in a week). But time.day gives a day-of-the-month from 1 to 31, so first you need to subtract one before the division and add one after. The first eight days of any month give…

    Day number    (Day# - 1) / 7    Week#
    ----------    --------------    -----
             1      0.0             1
             2      0.14            1
             3      0.29            1
             4      0.43            1
             5      0.57            1
             6      0.71            1
             7      0.86            1
             8      1               2
    

    Whichever day-of-the-week time.day gives, that week# indicates whether it’s the first, second etc of that day-of-the-week. But you want the coming Sunday.

    wday gives a weekday – 0 to 6, with 0 meaning Sunday. So how many days are there to the coming Sunday? Well, that depends on your definition of “Coming”, but if you exclude today==Sunday, you basically subtract todays weekday from 7.

    Weekday today     Days until next Sunday
    -------------     ----------------------
     0 (Sun)           7
     1 (Mon)           6
     2 (Tue)           5
     3 (Wed)           4
     4 (Thu)           3
     5 (Fri)           2
     6 (Sat)           1
    

    If you allow the “coming” Sunday to be today, then you do the same thing but replace seven with zero. You can either do a conditional check, or use the modulo/remainder operator.

    Anyway, once you know how many days ahead the coming Sunday is, you can calculate the date value for that (add those days to todays date) and then determine the week number in the month for that date instead of today using the first method (subtract 1, divide by seven, add 1).

    Relevant vocabulary…

    Date.wday        0 to 6 (0 = sunday)
    Date.day         1 to 31
    

    I won’t try to provide the code because I don’t know Ruby.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get the first character in a string using Ruby? Ultimately what
How can I determine if coordinate point lies within a polygon using Ruby?
Using Sinatra in Ruby you can set the server's settings by doing: set :myvariable,
I'm using Ruby on Rails to make an application where businesses can create accounts
I'm using Ruby on rails. Does somebody know how can I insert a javascript
I am using ruby 1.9.2 and sinatra 1.3.2, Datamapper I get error: can't convert
I'm working on an IMAP client using Ruby and Rails. I can successfully import
Question: How can I document Ruby code using Doxygen? Disclaimer: I know ruby already
I'm very new to Ruby and using Sinatra, mainly so that I can do
I was wondering how can I generate the following array using ranges in ruby

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.