We help IT Professionals succeed at work.

strtotime problem - different on two seperate servers

jset_expert asked
Hi I have an URGENT problem,

I have a site I have developed on my local machine, and I have recently uploaded the site to my hosting server.

My problem is all my dates, and date calculation are incorrect! I think I have pinpointed this to strtotime function.

example using this code:

      $birth = strtotime("20-05-1982");
      echo "<br>";
      echo ($birth);                  
      echo "<br>";
      echo "OUTPUT: " . date("d-M-y",$birth);
      echo "<br>";

output locally is;
       OUTPUT: 20-May-82

output on remote server is;
        OUTPUT: 03-Oct-25

differences between local and remote;
  - the server is hosted in US, whereas i'm in Australia
  - Local PHP version 5.2.4, remote is 4.4.7

i think the server is converting the str to time in yyyy mm dd format, but WHY?????

this is quite urgent, so any help is HUGELY appreciated.

Watch Question

The problem is that some countries use MONTH-DAY-YEAR and not DAY-MONTH-YEAR, like America for example. You could flip the date around to make sure it always works:
$birthDate = "20-05-1982";
list($day, $month, $year) = explode('-', $birthDate);
$birthTime = mktime(0, 0, 0, $month, $day, $year);
echo "<br>";
echo ($birthTime);                  
echo "<br>";
echo "OUTPUT: " . date("d-M-y",$birthTime);
echo "<br>";

Open in new window


cool that worked.

i was using strtotime, which seems to be unreliable.

i changed my strtotime functions to mktime, and it all worked OK!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.