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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:17:57+00:00 2026-06-18T10:17:57+00:00

echo date(‘Y-m-d’, strtotime(‘First Monday ‘.date(‘F o’, strtotime(-4 months))); The above code returns 2012-10-08, which

  • 0
 echo date('Y-m-d', strtotime('First Monday '.date('F o', strtotime("-4 months")));

The above code returns 2012-10-08, which is incorrect – the first monday of october 2012 should return 2012-10-01.

The changelog from the manual (http://php.net/manual/en/function.strtotime.php) specifies the following:

In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a 
month where that weekday was the first day of the month would incorrectly add
one week to the returned timestamp.

This has been corrected in 5.2.7 and later versions.

It seems to be clear that this is what’s causing the wrong return date, however I’m using PHP version 5.4.7 (running xamp on localhost)!

Any ideas?

  • 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-18T10:17:59+00:00Added an answer on June 18, 2026 at 10:17 am

    You are missing the keyword of when trying to retrieve the first day of the month

    echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));
    

    I found the info on this bug report

    My current version is PHP 5.4.4 in case it still does not work for you

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

Sidebar

Related Questions

PHP code: echo date(c); //out put like this 2012-06-19T20:37:44+05:30 echo date(d M, Y); //out
Is that normal that this line: echo date(Y-m-d h:m:s a, strtotime('2012-03-18 12:55:00')) gives me
$day = date('l', strtotime('07/25/2010')); echo $day ; echo date(m/d/Y, strtotime(first $day)); This prints out
This was working fine yesterday with no changes to the code. echo date(M, strtotime(-3
echo date('Y-m-d h:m:s',strtotime('2008-11-03 16:00:29')) Returns 2008-11-03 04:11:29 I've tried changing my default time zone
i've got code $dss='2011 04 28 10:00:45'; echo date('Y', strtotime($dss)); it display 1970- why?
Comment is the output I'm seeing. Help! echo date(Y-m-t, strtotime(2012-07-31 -1 month)); //2012-07-31 echo
Code first echo time() . '<br/>'; echo date('Y-m-d H:i:s') . '<br/>'; date_default_timezone_set('America/New_York'); echo time()
I wrote this piece of code echo date(Y-m-d, strtotime($date, strtotime(+ . $days . days)));
I try to do this echo date(Y, strtotime(1999-00-00)); but instead of 1999 it returns

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.