By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

mktime() and UNIXTIME epoch.

P: n/a
Hi.

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?

--
Sandman[.net]
Jul 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Hi Sandman!

On Wed, 18 Feb 2004 09:59:52 +0100, Sandman <mr@sandman.net> wrote:
Hi.

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. The SQL-92 functions ar much more
rudimentary than what PHP offers, but with some regexes you should get
something going. For dates before 1908 you should ask anyway "Where?",
I was amazed reading Joe Celko's "SQL for Smarties"

HTH, Jochen
Jul 17 '05 #2

P: n/a
In article <je********************************@4ax.com>,
Jochen Daum <jd@jdaum.de> wrote:
Hi.

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.

--
Sandman[.net]
Jul 17 '05 #3

P: n/a
Hi Sandman!

On Wed, 18 Feb 2004 10:51:08 +0100, Sandman <mr@sandman.net> wrote:
In article <je********************************@4ax.com>,
Jochen Daum <jd@jdaum.de> wrote:
>Hi.
>
>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...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.

HTH, Jochen

Jul 17 '05 #4

P: n/a
In article <5h********************************@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...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

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".

--
Sandman[.net]
Jul 17 '05 #5

P: n/a
Hi Sandman!

On Wed, 18 Feb 2004 12:00:19 +0100, Sandman <mr@sandman.net> wrote:
In article <5h********************************@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...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/
Jul 17 '05 #6

P: n/a
In article <f7********************************@4ax.com>,
Jochen Daum <jo*********@cans.co.nz> wrote:
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.


Well, the unix epoch is system-dependant, on some unix systems it's frm 1970,
and from some it's 1904. It all depends on whether the date integer can handle
inverse values (i.e. 0 is 1970-01-01 00:00:00 and -1 is 1969-12-31 23:59:59).
It's the scope of a 32 bit integer.
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.


Yes, it seems they don't use the system date functions, and I was hoping to
find a way to make PHP do the same... :/

--
Sandman[.net]
Jul 17 '05 #7

P: n/a

"Sandman" <mr@sandman.net> wrote in message
news:mr**********************@news.fu-berlin.de...
In article <f7********************************@4ax.com>,
Jochen Daum <jo*********@cans.co.nz> wrote:
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".

it seems they don't use the system date functions, and I was hoping to
find a way to make PHP do the same... :/


How about returning -1420052400 instead?

Have you looked at ADOdb?

I've a scratch page with various conversions at
http://www.boclair.com/adodb_test-time2.php.

Louise
Jul 17 '05 #8

P: n/a
In article <c1*************@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpond.net.au> wrote:
> 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".

it seems they don't use the system date functions, and I was hoping to
find a way to make PHP do the same... :/


How about returning -1420052400 instead?

Have you looked at ADOdb?

I've a scratch page with various conversions at
http://www.boclair.com/adodb_test-time2.php.


Hello - that looks nice!

What is ADOdb? How do I get the adodb.inc.php file?

--
Sandman[.net]
Jul 17 '05 #9

P: n/a

"Sandman" <mr@sandman.net> wrote in message
news:mr**********************@news.fu-berlin.de...
In article <c1*************@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpond.net.au> wrote:
What is ADOdb? How do I get the adodb.inc.php file?


A GPL program consisting of libraries and PHP classes which standardizes
access across many (most) database programs. Does much more than just
date/time conversions. Very powerful.

See http://php.weblogs.com/adodb .

To begin you might find the following useful.
http://www.phpfreaks.com/tutorials/110/0.php

Louise

Jul 17 '05 #10

P: n/a
In article <c1*************@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpond.net.au> wrote:
What is ADOdb? How do I get the adodb.inc.php file?


A GPL program consisting of libraries and PHP classes which standardizes
access across many (most) database programs. Does much more than just
date/time conversions. Very powerful.

See http://php.weblogs.com/adodb .

To begin you might find the following useful.
http://www.phpfreaks.com/tutorials/110/0.php


Ok, now I'm confused. This seems to be a Database bridge API, to make the
database backend to a PHP frontend interchangeable.

Well, first off - that seems a bit tad over the top to implement just to do
what I wanted.

And second - how do I know that the function adodb_mktime() doesn't use a
database backend to perform this query and it is the functions of THAT database
that enables mktime() to reference dates older than 1970?

Now, presumably I could just download it and look at the source - but posting
this was more fun. :)

--
Sandman[.net]
Jul 17 '05 #11

P: n/a
The central purpose of ADOdb is, as you say, to allow standardized
connections to various db engines and to query, insert etc data table
through php scripting.

However once results have been got there are a number of functions available
for manipulating the
result variables, including date/time. However the variables can be
created in any manner including directly as in the scratch page at
http://www.boclair.com/adodb_test-time2.php

The library is very light but if you want to slim it down further,
adodb-time.inc.php is the effective include. (adodb.inc.php is needed to
access it).

The functions are at http://php.weblogs.com/adodb_date_time_library.

Louise
The central purpose of ADOdb is, as you say, to allow standardized
connections to various db engines and to query, insert etc data table
through php scripting.

However once results have been got there are a number of functions available
for manipulating the
result variables, including date/time. However the variables can be
created in any manner including directly as in the scratch page at
http://www.boclair.com/adodb_test-time2.php

The library is very light but if you want to slim it down further,
adodb-time.inc.php is the effective include. (adodb.inc.php is needed to
access it).

The functions are at http://php.weblogs.com/adodb_date_time_library.

Louise

"Sandman" <mr@sandman.net> wrote in message
news:mr**********************@news.fu-berlin.de...
In article <c1*************@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpond.net.au> wrote:
What is ADOdb? How do I get the adodb.inc.php file?
A GPL program consisting of libraries and PHP classes which standardizes access across many (most) database programs. Does much more than just
date/time conversions. Very powerful.

See http://php.weblogs.com/adodb .

To begin you might find the following useful.
http://www.phpfreaks.com/tutorials/110/0.php


Ok, now I'm confused. This seems to be a Database bridge API, to make the
database backend to a PHP frontend interchangeable.

Well, first off - that seems a bit tad over the top to implement just to

do what I wanted.

And second - how do I know that the function adodb_mktime() doesn't use a
database backend to perform this query and it is the functions of THAT database that enables mktime() to reference dates older than 1970?

Now, presumably I could just download it and look at the source - but posting this was more fun. :)

--
Sandman[.net]

Jul 17 '05 #12

P: n/a
In article <c1*************@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpond.net.au> wrote:
The central purpose of ADOdb is, as you say, to allow standardized
connections to various db engines and to query, insert etc data table
through php scripting.

However once results have been got there are a number of functions available
for manipulating the
result variables, including date/time. However the variables can be
created in any manner including directly as in the scratch page at
http://www.boclair.com/adodb_test-time2.php

The library is very light but if you want to slim it down further,
adodb-time.inc.php is the effective include. (adodb.inc.php is needed to
access it).

The functions are at http://php.weblogs.com/adodb_date_time_library.


Regardless of databases, the TIME functions was seperately downloadable, and
they work just fine!

Thanks!

--
Sandman[.net]
Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.