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 7591883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:45:46+00:00 2026-05-30T20:45:46+00:00

I am trying to do some date math based on the week number of

  • 0

I am trying to do some date math based on the week number of a given year. For example:

date = Date.today # Monday, March 5, 2012
puts date.cwyear  # 2012
puts date.cweek   # 10 (10th week of 2012)

Now that I know what the current week is, I want to figure out what the next week and previous week are. I need to take the year (2012) and the week number (10) and turn it back into a date object so I can calculate the value for the next/previous week. How can I do this?

  • 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-05-30T20:45:47+00:00Added an answer on May 30, 2026 at 8:45 pm

    You want Date.commercial:

    require 'date'
    now = Date.today                                           #=> 2012-03-05
    monday_next_week = Date.commercial(now.cwyear,now.cweek+1) #=> 2012-03-12
    next_sunday_or_today = monday_next_week - 1                #=> 2012-03-11
    

    Note that weeks start on Monday, so if you are on a Sunday and ask for next monday – 1 you’ll get the same day.

    Note also that if you don’t want Mondays you can also specify the day number in the method:

    thursday_next_week = Date.commercial(now.cwyear,now.cweek+1,4) #=> 2012-03-15
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do some date math in Visual Basic. The NETWORKDAYS function in
I am trying to write some code to correctly set an expiration date given
I am trying to get today's date with some specific format: var d =
I'm trying to style some cells of a jquery-ui date picker based on application
I'm trying to set some components of todays date with NSDateComponent like so: NSDateComponents
I'm trying to make a date to appear as Fri, Feb 17 2012 instead
I am trying to use Datejs for some date functions. But I am not
I am trying to create some Issue Filters in JIRA based on CreateDate .
I am currently trying to display the number and date(string format) of a json
I'm trying to do some basic date and timestamp operations in PHP and have

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.