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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:44:26+00:00 2026-05-28T04:44:26+00:00

<?php $firstdate = ‘2011-11-16’; $sample = date(d-m-Y, strtotime($firstdate)); echo $sample; ?> I have a

  • 0
<?php 
$firstdate = '2011-11-16';
$sample = date("d-m-Y", strtotime($firstdate)); 
echo $sample;
?>

I have a column in a table with date in this format 2011-11-16
But I need it in reverse, so I’ve used the following code.

The problem is that when the date is 0000-00-00, it prints 01-01-1970.
Is there a way of making it print 00-00-0000 instead? Please note that I’m looking to reverse it to British format. 00-00-0000.

Thanks

  • 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-28T04:44:26+00:00Added an answer on May 28, 2026 at 4:44 am

    The problem is in the way dates are represented internally. They use what’s called Unix time, in which the date is represented as a number of seconds after the “Unix epoch”, which is 1/1/1970. This is why the date function (correctly) represents 0 (which is what strtotime returns when you pass it 0000-00-00) as Jan 1, 1970.

    The only solution I can think of is something like this:

    <?php 
    $firstdate = '2011-11-16';
    $sample = $firstdate == '0000-00-00' ? '00-00-0000' : date("d-m-Y", strtotime($firstdate)); 
    echo $sample;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of php arrays that look like this (please don't ask
I have the following PHP PDO statement: $STH = $this->_db->prepare(INSERT INTO UserDetails (FirstName, LastName,
Suppose that I have a date Jan 31 2011 and I want to add
Possible Duplicate: PHP MySQL Search And Order By Relevancy Hi, I have a table
I have a small PHP mysql query looking at a table in my database.
my php code looks like this: $result['firstName']['lastName']='johan'; echo json_encode($result); how should i type to
sendmail.php This is just sample of attachment.in which i m confused... class sendmail() public
I have a php multidimensional array populated from a table using the following code:
I am able to convert the date (2011-01-05 to 05 January 2011) using: <?php
I have a weird date format in some files I'm parsing. Here are some

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.