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

  • Home
  • SEARCH
  • 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 8939179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:46:22+00:00 2026-06-15T10:46:22+00:00

I am having a problem with php’s DateTime functions. Today is monday 3 december.

  • 0

I am having a problem with php’s DateTime functions.
Today is monday 3 december.

Assuming the following code:

$dte = new DateTime(date('Y-m-d H:i:s'));
var_dump($dte->format('Y-W'));
$dte->modify('+4 weeks');
var_dump($dte->format('Y-m-d H:i:s -- Y_W'));
$dte->modify('+1 days');
var_dump($dte->format('Y-m-d H:i:s -- Y_W'));

After four weeks it would be 31st of december. I would suspect to get the last week of the year (52?). But what I get is week 1 of 2012 as you can see in the following output.

string '2012-49' (length=7)
string '2012-12-31 14:48:00 -- 2012_01' (length=30)
string '2013-01-01 14:48:00 -- 2013_01' (length=30)

So my problem is that after the first modification I think I should get:

2012-12-31 14:48:00 -- 2012_52

but instead I get

2012-12-31 14:48:00 -- 2012_01

So why does the week go back to 01 without incrementing the year, and than why does the other line gives me 2013_01 ?

EDIT::
I now see that the week before is week 52, anything to do with leap year?
But then again, how can the week go back to 01 without incrementing the year?

  • 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-15T10:46:23+00:00Added an answer on June 15, 2026 at 10:46 am

    So why does the week go back to 01 without incrementing the year, and than why does the other line gives me 2013_01 ?

    I think you’re displaying the “year” instead of the “week-year”. When you’re using week numbers, it’s the week-year that’s the relevant part; simple “year” is only relevant with respect to month and day.

    EDIT: I think you want the o format specifier instead, so try:

    var_dump($dte->format('Y-m-d H:i:s -- o_W'));
    

    That should show you 2013_01 for December 31st 2012, as it’s in week 1 of week-year 2013.

    So basically, I don’t think this is a bug in DateTime – it’s just a misunderstanding of how “week of year” is meant to be used.

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

Sidebar

Related Questions

I'm having a problem with PHP. I want the following code to only show
I am having the following problem: Environment PHP, codeigniter framework with PDO. my code
I'm having a problem with a query prepared in PHP with PDO. The code:
I'm having a problem with some code that used to work in PHP 4.X
I'm having a strange problem with php PDO and mysql. I have the following
I am having a weird problem with PHP's DateTime diff method. I've been using
I'm new to MySQL and I'm having problem with a query using PHP. See
I am new to PHP OOP and I am having problem getting arrays back.
I'm having a problem with some PHP code I'm trying to use. I keep
I am having problem with implementing custom session handler in php. The code: http://pastebin.com/9QV9f22Q

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.