LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP date functions (https://www.linuxquestions.org/questions/programming-9/php-date-functions-105053/)

cmfarley19 10-17-2003 05:40 AM

PHP date functions
 
I wrote a scrpit to dispay the time between two dates in YY years, MM months, DD days, HH hours, MM minutes, and SS seconds.

The script works fine for all dates after the UNIX epoch. The mktime() and date() functions are messing me up. I wrote a small test script and got the following results.
PHP Code:

<?

        $epoch1 
mktime000481969);
        
$epoch2 mktime0009201971);

        echo 
"epoch1 = ".date'F jS, Y'$epoch1 )." - ".$epoch1."<br><br>\n";
        echo 
"epoch2 = ".date'F jS, Y'$epoch2 )." - ".$epoch2."<br><br>\n";

?>

I would expect that to display $epoch1 as April 8th, 1969. Instead I get:
Code:

epoch1 = December 31st, 1969 - -1

epoch2 = September 20th, 1971 - 54187200

Any date prior to 1/1/1970 yields this result.

Any thoughts?

SaTaN 10-17-2003 08:58 AM

What happens is 1970 is taken as the reference for caluclation of date.
Maybe incrementation of this time takes place until the corresponding month,day,year specified by mktime are got .
If i remember right , epoch returns the seconds passed from Jan 1st,1970 to time specified by mktime.
Hence when you specify the date of less than that of 1970..then the correct time cannot be calculated ....I suppose I have made myself clear.

Epoch returns the value of
secs_passed = secs(date_specified_by_mktime)-secs(1970,Jan 1)
where secs(1970,Jan1 ) is taken as starting value =0;

if secs_passed is negative i.e, date_specified < 1970,Jan1 then -1will be printed


All times are GMT -5. The time now is 07:20 AM.