473,666 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mktime() and UNIXTIME epoch.

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
12 3291
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
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
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
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
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
In article <f7************ *************** *****@4ax.com>,
Jochen Daum <jo*********@ca ns.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

"Sandman" <mr@sandman.net > wrote in message
news:mr******** **************@ news.fu-berlin.de...
In article <f7************ *************** *****@4ax.com>,
Jochen Daum <jo*********@ca ns.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
In article <c1************ *@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpon d.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

"Sandman" <mr@sandman.net > wrote in message
news:mr******** **************@ news.fu-berlin.de...
In article <c1************ *@ID-210679.news.uni-berlin.de>,
"boclair" <bo*****@bigpon d.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2502
by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0)) 3600.0 >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 1)) 0.0 >>> time.mktime((1969, 12, 31, 16, 0, 0, 0, 0, 1))
2
4701
by: Florian Quetting | last post by:
Hi, I'm getting mad with following problem: The code compiles, but I always get a segfault and I don't have any clue why. I can't see any differences in my way of calling mktime and others. --------------------------------------------------------------------------- #include <iostream> #include <sys/stat.h>
4
10237
by: McBooCzech | last post by:
Hi, on Linux (Fedora FC4) and Python 2.4.1 I am trying to know the time delta in seconds between two times given in the HHMMSS format. My code looks like: import datetime, time ta1=(time.strptime('000001', '%H%M%S')) ta2=(time.strptime('230344', '%H%M%S')) t1=time.mktime(ta1) t2=time.mktime(ta2) print t1, t2
16
14328
by: John Hanley | last post by:
I created a function that breaks down a date into broken down time, I subtract a certain number of seconds from that, then use mktime() to recompute the calendar time. It works basically except every so often, I get the date 060207 (Feb 7, 2006) which is obviously not correct. When it does this it always gives me this date. I tracked it down to my mktime() call, when I get to a certain date, mktime returns a number in 4000000000,...
2
1485
by: KfirShtober | last post by:
Hello. I have a task to develop a calendar in C#, therefore - I need to use unixtime I think. But I don't know how to, can some one explain to me how to convert the date of today to unix time? And how can I add a day to the unixtime of today for example. Thx guys.
3
6279
by: Mark | last post by:
I want to simply get the unix style epoch time (number of secs to now from Jan 01, 1970 UTC) for use as a timestamp to track the staleness of some objects. So I don't care about time zones or whatever as long as it's consistent. So I picked the epoch time UTC getting the value I wanted, "timestamp", this way: #include "boost/date_time/local_time/local_time.hpp" using namespace boost::gregorian; using namespace boost::local_time;
4
6075
by: xoinki | last post by:
hi all, I am trying to calculate a timestamp in unix epoch (number of seconds from 1/1/1970) from date and time info. The tm structure is filled as follows. tm_sec 55 tm_min 6 tm_hour 12 tm_mday 28 tm_mon 11 tm_year 107 // 2007 - 1900
1
2668
by: smitanaik | last post by:
hi i have unixtime format 1075329297.572 how do i store it in database.that is with what datatype.i tried to store unixtime using date, timestamp but it does not work. but with varchar2 it works. but ifi store with varchar2 i cant perform conversion functions. i want to convert unix time into yyyy-dd-mm hh-mm-ss format. help me out thanks in advance
5
2185
by: Robert Latest | last post by:
Here's what happens on my Windows machine (Win XP / Cygwin) at work. I've googled a bit about this problem but only found references to instances where people referred to dates before the Epoch. Of course at home on my Linux box everything works. I know that everything has its limits somewhere, but I've never heard of March 2008 being a problem. Tomorrow I'm going to write a test loop that shows me the exact last
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.