473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Slow performance using strtotime on prior 1970 dates

cla
I'm using this code on an application to track football schedules:
----
$season = '2005';
$basedate = strtotime('this friday', strtotime('31 August '.$season));

for($d=0;$d<=31;$d++) {
$d2=strtotime("+".$d." day",$basedate);
echo(date('m d Y',$d2)."\n");
}
----
The purpose is to find the first Friday on or after Aug. 31 in a given
year. Plug '2005' into $season, and it flies through. Plug in
'1905', however, and each step in the for loop takes about .5 sec.
I'm running this code in PHP 5.2.1. Any ideas?

Sep 14 '07 #1
5 2494
Well the fact is 1970 was when the Unix Epoch started, so any dates
prior to that date are much more slower. I don't know why, but try on
a Windows machine and see if the same happens. Probably it's just on
*nix systems.

Sep 14 '07 #2
On Sep 14, 3:22 pm, cla <cla...@gmail.comwrote:
I'm using this code on an application to track football schedules:
----
$season = '2005';
$basedate = strtotime('this friday', strtotime('31 August '.$season));

for($d=0;$d<=31;$d++) {
$d2=strtotime("+".$d." day",$basedate);
echo(date('m d Y',$d2)."\n");}

----
The purpose is to find the first Friday on or after Aug. 31 in a given
year. Plug '2005' into $season, and it flies through. Plug in
'1905', however, and each step in the for loop takes about .5 sec.
I'm running this code in PHP 5.2.1. Any ideas?
If all you want to do is find the first Friday on or after August 31
why do you need the loop?

Sep 14 '07 #3
cla
On Sep 14, 12:59 pm, ZeldorBlat <zeldorb...@gmail.comwrote:
On Sep 14, 3:22 pm, cla <cla...@gmail.comwrote:
I'm using this code on an application to track football schedules:
----
$season = '2005';
$basedate = strtotime('this friday', strtotime('31 August '.$season));
for($d=0;$d<=31;$d++) {
$d2=strtotime("+".$d." day",$basedate);
echo(date('m d Y',$d2)."\n");}
----
The purpose is to find the first Friday on or after Aug. 31 in a given
year. Plug '2005' into $season, and it flies through. Plug in
'1905', however, and each step in the for loop takes about .5 sec.
I'm running this code in PHP 5.2.1. Any ideas?

If all you want to do is find the first Friday on or after August 31
why do you need the loop?
The loop's more for a demo. In the live app, there's a drop down list
of possible dates within a given week of a season. The first Friday
is just the starting point from which all subsequent dates are
referenced.

Sep 14 '07 #4
cla
On Sep 14, 12:24 pm, RageARC <rage...@gmail.comwrote:
Well the fact is 1970 was when the Unix Epoch started, so any dates
prior to that date are much more slower. I don't know why, but try on
a Windows machine and see if the same happens. Probably it's just on
*nix systems.
Made a quick test on a Windows box, and the performance seems to be
about the same.

Sep 14 '07 #5
Well, I searched, and I found the following:

The valid range of a timestamp is typically from Fri, 13 Dec 1901
20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates
that correspond to the minimum and maximum values for a 32-bit signed
integer.) Additionally, not all platforms support negative timestamps,
therefore your date range may be limited to no earlier than the Unix
epoch. This means that e.g. dates prior to Jan 1, 1970 will not work
on Windows, some Linux distributions, and a few other operating
systems. PHP 5.1.0 and newer versions overcome this limitation though.

Yep, 5.1.0 overcomes this limitation, but at a much slower pace.

Sep 14 '07 #6

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

Similar topics

5
by: ruud habets | last post by:
while making an encyclopdie on my hometown (dutch, http://www.kgv.nl/index.php?id=610) i am trying to use dates prior to 1970. birthdates in, let's say, 1615. i'm getting errors while working...
1
by: sylvian stone | last post by:
Hi, I've used standard date functions in the past, but need to create something a little different, as I am working on an investment calculator. What I need to do is validate two dates, and...
4
by: psql-mail | last post by:
I am running a SELECT to get all tuples within a given date range. This query is much slwoer than i expected - am i missing something? I have a table 'meta' with a column 'in_date' of type...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
2
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is...
2
by: Baron Samedi | last post by:
if I code $birth = strtotime('1 April 1950'); then $birth = -1, I guess that this is because time "began" on 1st Jan, 1970. (although I seem to remember a few good times before that). So,...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
6
by: Brandon | last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a...
9
by: Erwin Moller | last post by:
Hi group, I have been using strtotime a lot in my code. I wonder if I made a mistake in my thinking. :-/ Here follows a stripped down example. consider some dates: $date1 = "2008-02-23";...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.