homepage Welcome to WebmasterWorld Guest from 54.204.128.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Strtotime on different servers
Pollos




msg:4125671
 11:29 am on May 2, 2010 (gmt 0)

Hi
Can anyone enlighten me as to why the following code:

$date = "31-12-2009";
for ($i = 1; $i <= 365; $i++) {
$newdate = strtotime ( '+1 day' , strtotime ( $date ) ) ;
$newdate = date ( 'd-m-Y' , $newdate );
$timestamp = strtotime($newdate);
echo "(",$i, ", '",$newdate,"', ",$timestamp,")<br>";
$date = $newdate ;
}


Outputs:
(1, '01-01-2010', 1262300400)
(2, '02-01-2010', 1262386800)
(3, '03-01-2010', 1262473200)
(4, '04-01-2010', 1262559600)
(5, '05-01-2010', 1262646000)......
On my local server [windows + XAMPP php ver 5.28]

but on my webhosts server it outputs:
(1, '01-06-2037', 1167260400)
(2, '29-12-2006', 2064002400)
(3, '30-05-2035', 2079558000)
(4, '26-11-2035', 1969221600)
(5, '28-05-2032', 2016226800).......
[php ver4.49]


I'm trying to populate a MYSQL database with:
[ID] -- [date] -- [timestamp]
'1' '01-06-2037' '1167260400'

So I can calculate dates
I have my site working perfectly locally but when I uploaded it nothing would work.

 

IanKelley




msg:4125824
 9:24 pm on May 2, 2010 (gmt 0)

Have you tried uploading it to a different web server?

eelixduppy




msg:4125844
 10:13 pm on May 2, 2010 (gmt 0)

Try this real quick:


$date = "2009-12-31";

Pollos




msg:4126183
 4:07 pm on May 3, 2010 (gmt 0)

IanKelley Thank you I did try it on a VPS I have and it works perfectly with and without eelixduppy suggested change.

eelixduppy Thank you I did try the change you suggested, not sure if I was quick enough but it just gives a similar munged output:

(1, '01-01-2010', 1151877600)
(2, '04-07-2006', 1261868400)
(3, '28-12-2009', 2032725600)
(4, '02-06-2034', 1198537200)
(5, '26-12-2007', 1969394400)
(6, '30-05-2032', 2079298800)
(7, '23-11-2035', 1874527200)
(8, '28-05-2029', 2015967600)
(9, '20-11-2033', 1779746400)
(10, '27-05-2026', 1984086000).......

Can anyone give me a clue as to where the problem may lie [it's a shared hosting acc with 1&1] so I can have a moan at them about it.

Thank once again.

Matthew1980




msg:4126196
 4:27 pm on May 3, 2010 (gmt 0)

Hi there Pollos,

I have just tested your code on my local host & my server, and there output is identical(correct, no jumps in dates at all), are the servers your uploading to in the same or different time zones? Just a thought there...

So from what I can see there is nothing wrong with the code, though I am dubious of reusing the $newdate var twice. A little confusing ;)

Cheers,
MRb

Pollos




msg:4126214
 4:52 pm on May 3, 2010 (gmt 0)

Hi Matthew

I have two accounts with 1&1, the script works fine on my VPS running Cent I believe, with PHP Version 5.1.6

The site I'm working on is on shared hosting again with 1&1. Operating system ? PHP Version 4.4.9

$newdate, yes you are correct, in my original script it was $newday = strtotime ( '+1 day' , strtotime ( $date ) ) ;

I think I'll have to have a word with 1&1's tech dept, unless anyone has any other ideas.

Matthew1980




msg:4126223
 5:10 pm on May 3, 2010 (gmt 0)

Hi there Pollos,

Well it certainly seems to be having an effect, my host is UK based, and my laptop is in Wales! Though the time zone is the same :) At least it's not the script that's at fault.

The only thing I will add, is that my local is windows & my server is linux, and this seems to have no effect, not that it should, but just to cover that base ;)

Cheers,
MRb

IanKelley




msg:4126224
 5:12 pm on May 3, 2010 (gmt 0)

Having tried it on multiple servers I think you can be pretty sure the problem is on the server itself. Definitely an issue for their tech support.

Pollos




msg:4126242
 5:41 pm on May 3, 2010 (gmt 0)

Thanks guys I'll drop them a e-mail and await their reply.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved