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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:13:41+00:00 2026-06-01T00:13:41+00:00

$datetime = new DateTime(‘0000-00-00 00:00:00’); $date_string = $datetime->format(‘Y-m-d H:i:s’);//-0001-11-30 00:00:00 date gets turned from

  • 0
$datetime = new DateTime('0000-00-00 00:00:00');
$date_string = $datetime->format('Y-m-d H:i:s');//-0001-11-30 00:00:00 

date gets turned from 0000-00-00 00:00:00 to -0001-11-30 00:00:00
this is obviously wrong, why does this happen, how to fix it?
Should at least return false.

info:
PHP Version 5.2.13-0.dotdeb.1
Linux 2.6.26-2-openvz-amd64 #1 SMP Thu Nov 25 05:14:47 UTC 2010 x86_64

  • 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-01T00:13:42+00:00Added an answer on June 1, 2026 at 12:13 am

    It’s sort of correct by definition:

    • the zero-th day as opposed to the first yields a (hypothetical) minus one day
    • the zero-th month as opposed to the first yields a (hypothetical) minus one month

    Take the (hypothetical) 1st of Jan in the year 0, subtract a month -> 1st of Dec in the year -1.
    Subtract a day -> 30th of Nov in the year -1

    Alternatively, they could have chosen to fix up the day first, then it’d go like:
    1 Jan minus 1d -> 31st of Dec -0001, minus 1mo -> 30th of Nov -0001

    The formatter obviously does the bound check to only produce valid dates. (For some definition of “valid”)

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

Sidebar

Related Questions

I have this: var date = new DateTime(2009, 12, 5); ... ... and need
I have this simple code: DateTime date = new DateTime(dateValue); DateTime currentDate = new
I am using the following: $endtime = new DateTime(date('r', '1329717600')); $endtime->setTimezone(new DateTimeZone('America/Los_Angeles')); echo $endtime->format('w
Consider the following example quoted from php manual for DateTime <?php $date = new
I have URL: http://www.mysite.com/ here is: $date = new DateTime(2011-11-28); this show me: 2011-11-28
This works: $aWeekAfterDate = new DateTime(); $aWeekAfterDate->modify('+1 week'); $aWeekAfterDate->format('d.m.Y'); But this: $aWeekAfterDate = new
am I doing this wrong? DateTime previousDay = new DateTime(year, month, day); string test1
This is very weird. I have the following code: Assert.AreEqual(new DateTime(2000, 1, 1), DateTime.ParseExact(2000,
I know I can do this: IDateTimeFactory dtf = MockRepository.GenerateStub<IDateTimeFactory>(); dtf.Now = new DateTime();
I can have an extension method like this: DateTime d = new DateTime(); d

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.