1
date('m/d/Y', strtotime('7-Jan-69'))

It gives output as 01/07/2069, Where

date('m/d/Y', strtotime('7-Jan-75'))

This gives output as 01/07/1975, Why is so and what is the catch?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
mujaffars
  • 1,395
  • 2
  • 15
  • 35

3 Answers3

3

From the docs:

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC)

Any date before 1970 will be understand as date after 1970

Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
0

do you need something like this?

<? 
    // function to convert string and print 
    function convertString ($date) 
    { 
        // convert date and time to seconds 
        $sec = strtotime($date); 

        // convert seconds into a specific format 
        $date = date("Y-m-d H:i", $sec); 

        // append seconds to the date and time 
        $date = $date . ":00"; 

        // print final date and time 
        echo $date; 
    } 

    // Driver code 
    $date = "06/12/2014 04:13 PM"; 
    convertString($date); 
?> 
0

To fix that you can use DateTime instead of strtotime() like below,

<?php
$date = $dt = new DateTime('7-Jan-75');
echo $date->format('m/d/Y');
?>

Reason for not working in your case with strtotime:

If the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999. See the notes below for possible differences on 32bit systems (possible dates might end on 2038-01-19 03:14:07).

DEMO: https://3v4l.org/d8eoK

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103