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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:14:32+00:00 2026-05-27T14:14:32+00:00

Is it possible to get the first / last date of a week using

  • 0

Is it possible to get the first / last date of a week using PHP’s Relative Date Time format?

I’ve tried to do:

date_default_timezone_set('Europe/Amsterdam');
$date = new DateTime();

$date->modify('first day of this week'); // to get the current week's first date
echo $date->format('Y-m-d'); // outputs 2011-12-19

$date->modify('first day of week 50'); // to get the first date of any week by weeknumber
echo $date->format('Y-m-d'); // outputs 2011-12-18

$date->modify('last day of this week'); // to get the current week's last date
echo $date->format('Y-m-d'); // outputs 2011-12-17

$date->modify('last day of week 50'); // to get the last date of any week by weeknumber
echo $date->format('Y-m-d'); // outputs 2011-12-18

As you can see it doesn’t output the correct dates.

According to the docs this should be possible if I’m correct.

Am I doing something terrible wrong?

EDIT

I need to use PHP’s DateTime for dates in the far future.

UPDATE

It gets only stranger now. I’ve done some more testing.

Windows PHP 5.3.3

2011-12-01

Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (first day of week 50) at position 13 (w): The timezone could not be found in the database in C:\Users\Gerrie\Desktop\ph\Websites\Charts\www.charts.com\public\index.php on line 9
2011-12-01
2011-11-30

Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (last day of week 50) at position 12 (w): The timezone could not be found in the database in C:\Users\Gerrie\Desktop\ph\Websites\Charts\www.charts.com\public\index.php on line 15
2011-11-30

Linux 5.3.8

2011-12-01
2011-12-01
2011-11-30
2011-11-30
  • 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-27T14:14:33+00:00Added an answer on May 27, 2026 at 2:14 pm

    According to docs the format strings “first day of” and “last day of” are only allowed for months, not for weeks. See http://www.php.net/manual/en/datetime.formats.relative.php

    If you combine first and last day of with a week statement the result either blows the parser or is something that you did not expect (usually the first or last day of a month, not a week).

    The difference that you see between Win and Linux is probably only because of different error reporting settings.

    To get the first and last day of the current week use:

    $date->modify('this week');
    $date->modify('this week +6 days');
    

    To get the first and last day of week 50 use:

    $date->setISODate(2011, 50);
    $date->setISODate(2011, 50, 7);
    

    EDIT:

    If you want to use the modify method for absolute week numbers you have to use the formats defined in http://www.php.net/manual/en/datetime.formats.compound.php:

    $date->modify('2011W50');
    $date->modify('2011W50 +6 days');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get first day of week in PHP? Hi, I want to find
Possible Duplicate: Get first day of week in PHP? i have this script that
Is it possible to get the first line of text from a UITextView. I
Is it possible to get the value from the first page to the second
Possible Duplicate: Get all files from VSS for a given date? I need to
Possible Duplicate: Regex - Return First and Last Name Hi, I have the full
Reference to pre-answered question at: Getting first and last days of current week There
Possible Duplicate: How to get first x chars from a string, without cutting off
Possible Duplicate: Get CVS history for a particular user Is it possible to list
Is it possible to get gdb or use some other tools to create 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.