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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:46:32+00:00 2026-05-25T23:46:32+00:00

I have run into an interesting issue using PHP’s date() function. Haven’t had any

  • 0

I have run into an interesting issue using PHP’s date() function. Haven’t had any luck locating a discussion of this on SO or using Google, but maybe someone else has run into the same issue before?

I am trying to get the YEAR and the WEEK OF THE YEAR for a given timestamp. This is the code I am using:

date("Y-\WW");

Which as of today correctly outputs: 2011-W39.

The problem is when supplying a timestamp, if the timestamp in question is, for example, on January 3rd, 2011 (which was actually part of the “52nd week of 2010”. PHP correctly returns W52, but it also returns 2011 as the year, instead of 2010.

date("Y-\WW", 1294016400);

Outputs: 2011-W52

Any idea on how to solve this problem? I should note that although in this case it would be easy to just compare that the strtotime() of the output is greater than the current time() and adjust, but I need a solution that will work for previous years as well (e.g. if the same thing happened for January 3rd 2010).

  • 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-25T23:46:33+00:00Added an answer on May 25, 2026 at 11:46 pm

    Darn, apparently I didn’t re-read the documentation closely enough, the letter o was added in PHP 5.1.0:

    From the documentation for date():

    ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)

    So my code should have been date("o-\WW");

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

Sidebar

Related Questions

I have run into an interesting problem. I am currently developing php page and
I have run into an issue with WPF and Commands that are bound to
I have run into a bit of a problem here: I had a problem-specific
I've run into an interesting issue.. It seems that ComputeHash() for a HMACSHA256 hash
I have run into an interesting bug where it appears that when you select
I have run into an interesting problem. I have inherited a database for daemon
I have run into an interesting dilema. In a DataMapper class, I am generating
I have run into an interesting problem lately: Lets say I have an array
I have run into an interesting error. I have created a PL/SQL Webservice in
I've run into an interesting problem here in using heroku + git + SVN.

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.