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

The Archive Base Latest Questions

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

How to compare two dates in php and echo newer one? My dates are

  • 0

How to compare two dates in php and echo newer one?

My dates are in the following format: date("F j, Y, g:i a"); which give us August 12, 2011, 9:45 am.

My dates are as follow:

  • date 1 $created
  • date 2 $updated / if no updated have been made value is 0000-00-00 00:00:00

Any suggestion much appreciated.

  • 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-24T14:14:12+00:00Added an answer on May 24, 2026 at 2:14 pm
    $date1 = new DateTime("August 12, 2011, 9:45 am");
    $date2 = new DateTime("August 12, 2011, 10:45 am");
    
    $never_date = ($date1<$date2)?$date1:$date2;
    
    echo $never_date->format("F j, Y, g:i a");
    

    But note, that 0000-00-00 00:00:00 is a valid input for DateTime(), but will not work as expected. It will result in a -0001-11-30 00:00:00 (at least for PHP 5.3-VC9-nts on Win7 x64).

    Update: I see two options for workarouning that 0000-00-00 00:00:00

    • Allow nulls in that column in your DB and remove DEFAULT 0000-00-00 00:00:00.
    • Check if $updated == '0000-00-00 00:00:00' and if so, just return $created:
    • Check if $updated == '' (empty string) and if so return $created:

      if ($updated=='0000-00-00 00:00:00' || $updated=='')
          $never_date = $created;
      else
          $never_date = ($created<$updated)?$created:$updated;
      

    I doubt that it’s right behaviour to show 0000-00-00 00:00:00 for a record that was never updated.

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

Sidebar

Related Questions

I have two dates: how do I compare which one is greater date in
I want to compare two dates in PHP. One date is the date due,
I want compare two dates one would be the current date and other date
I have to compare two dates where first date is in Calendar format and
How can I compare two dates in PHP? The date is stored in the
I am trying to compare two dates. I have this code which I thought
I need to compare two dates with time (am/pm). I used the following code.
How would I compare two dates to see which is later, using Python? For
Hi im trying to compare two dates in MySQL via a query, one is
Is there a way to compare two dates (which include time) ignoring the time?

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.