Re: mktime() and UNIXTIME epoch.

From: Jochen Daum (jochen.daum_at_cans.co.nz)
Date: 02/18/04


Date: Thu, 19 Feb 2004 08:47:26 +1300

Hi Sandman!

On Wed, 18 Feb 2004 12:00:19 +0100, Sandman <mr@sandman.net> wrote:

>In article <5hd630liph63pc5105l7r0ok0n70viphhq@4ax.com>,
> Jochen Daum <jd@jdaum.de> wrote:
>
>> >> >On my Linux RedHat 8 system, I can't obtain dates earlier than 1970 with
>> >> >PHP. That is, when feeding a function that turns dfates into unixtime,
>> >> >such as mktime() and strtotime()
>> >> >
>> >> > print date("Y-m-d", mktime(0,0,0,1,1,1930));
>> >> > -> "1969-12-31" (since the result of mktime is "-1")
>> >> >
>> >> >But date() gets it though, so if I do
>> >> >
>> >> > print date("Y-m-d", -1000000000);
>> >> > -> "1938-04-24"
>> >> >
>> >> >Now, presumably this has something to do with Linux instead of PHP,
>> >> >since doing this in MySQL doesn't work either:
>> >> >
>> >> > select unix_timestamp('1935-12-03');
>> >> > -> 0
>> >> >
>> >> >But, when using perl, it works just fine when using Date::Manip:
>> >> >
>> >> > #!/usr/bin/perl
>> >> > use Date::Manip; $date = UnixDate("1945-01-23", "%s"); print $date;
>> >> > -> -787021200
>> >> >
>> >> >So, how come MySQL can't do it, PHP can't do it, but somehow perl can?
>> >> >Can I compile PHP with negative integer date support?
>> >>
>> >> I think it depends on the underlying unix libraries. I think a better
>> >> approach would IMO to write a library based on the MySQL date functions
>> >> (or any other database), which should support date support from 1908-xxxx
>> >> or earlier.
>> >
>> >Eh, I don't understand... Are you recommending I use MySQL to obtain dates
>> >earlier than 1970 even though I showed above that MySQL doesn't support it
>> >either...? I am confused.
>> >
>> >To recap again. MySQL doesn't support it, PHP doesn't support it, Perl
>> >supports it.
>>
>> If you look at http://www.mysql.com/doc/en/Date_and_time_functions.html
>>
>> and just do not use any %UNIX% functions, you should be fine. I just tested
>>
>> SELECT INTERVAL 1 DAY + '1925-12-31'
>>
>> and its New Years day 1926.
>
>I realize that - but perhaps I was unclear at what I wanted. I WANT the unix
>timestamp of a given date.
>
>select unix_timestamp("1985-01-01");
> -> 473382000
>
>select unix_timestamp("1925-01-01");
> -> 0

Thats because the Unix Epoch is from 1970 to 2038. The result is IMO
undefined for dates outside.

>
>What that other select SHOULD return is "-1420074000" and THAT's what I want. I
>want a function, prefferably in PHP, that will return "-1420074000" when I feed
>it with "1925-01-01".

Its an understandable opinion, but I would dicuss it with the guys
that do the unix date libraries. That might clear it.

HTH, Jochen

-- 
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/


Relevant Pages