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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:14:33+00:00 2026-05-22T22:14:33+00:00

I am looking for a Perl script which can give me the last Monday

  • 0

I am looking for a Perl script which can give me the last Monday for any specified date.

e.g. For date 2011-06-11, the script should return 2011-06-06

  • 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-22T22:14:34+00:00Added an answer on May 22, 2026 at 10:14 pm

    I’m assuming that if the given date is a Monday, you want the same date (and not the previous Monday). Here’s one way to do it with DateTime:

    use DateTime;
    
    my $date = DateTime->new(year => 2011, month => 6, day => 11);
    my $desired_dow = 1;            # Monday
    $date->subtract(days => ($date->day_of_week - $desired_dow) % 7);
    print "$date\n";
    

    (Actually, for the special case of Monday, the % 7 isn’t necessary, because $date->day_of_week - 1 will always be 0–6, and that mod 7 is a no-op. But with the % 7, it works for any desired day-of-week, not just Monday.)

    If you did want the previous Monday, you can change the subtraction:

    $date->subtract(days => ($date->day_of_week - $desired_dow) % 7 || 7);
    

    If you need to parse a date entered on the command line, you might want to look at DateTime::Format::Natural.

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

Sidebar

Related Questions

I have a perl script (or any executable) E which will take a file
I'm trying to update some existing code that normally runs a Perl script which
I've written a perl script that opens two files which contain lists. I want
I've got a Perl script that groks a bunch of log files looking for
I am trying to insure that only one instance of a perl script can
My problem is: I have a perl script which uses lot of memory (expected
Looking to execute a perl script on a remote machine via a Perl script.
I am looking for some examples/advice on how to write a Perl script to
Possible Duplicate: How can I fire and forget a process in Perl? I'm looking
I have a Perl script that I've written and can compile it using pp

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.