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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:34:10+00:00 2026-06-09T11:34:10+00:00

I am new to ruby on rails and got stuck in dates. I used

  • 0

I am new to ruby on rails and got stuck in dates. I used Time.now to get the current time. Now I want to find out the srart and end dates for the current week and current month. For instance:

If Time.now returns me –

2012-08-13 15:25:35 +0530

Then the start and end dates for the current week are:

2012-08-12 - 2012-08-18

Then the start and end dates for the current month are:

2012--08-01 - 2012-08-31

I am implementing the same using the code:

Time.now.wday   
 => 1 

Time.now - 1.day
=> 2012-08-12 15:31:44 +0530 

Time.now + 5.day
 => 2012-08-19 15:32:38 +0530

and so on.. But I dont find it a convenient way to do this. Iam sure Ruby on Rails does hold a better solution. Can anyone suggest to figure out the same..

  • 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-09T11:34:11+00:00Added an answer on June 9, 2026 at 11:34 am

    Instead of using Time.now

    Use the following code to get your queries solved

    d = Date.today
    
    d.at_beginning_of_week
    #Mon, 13 Aug 2012
    d.at_beginning_of_week.strftime
    #"2012-08-13"
    d.at_beginning_of_week.strftime("%d")
    #"13" -> To print the date.
    

    Similarly you can find multiple methods in the Date Class

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

Sidebar

Related Questions

I'm a new user of Ruby on rails and I try now to create
To begin, I am very new to Ruby on Rails. So I want to
New to both Ruby and Rails but I'm book educated by now (which apparently
New to rails/ruby (using rails 3 and ruby 1.9.2), and am trying to get
I'm new to ruby on rails (and ruby) and I'm trying to get ActiveAdmin
I'm new to ruby on rails, and I'm having an issue with the find
I'm new to ruby/rails and trying to build a simple Projects / Tags app
I'm new in Ruby/Rails, so, my question: what is the perfect way to upload
I'm currently evaluating options for adding sub-domain support to a new Ruby on Rails
I am new to Ruby on Rails and I am trying to make a

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.