Welcome to WebmasterWorld Guest from 54.163.23.73

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Strtotime on different servers

     

Pollos

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



Have you tried uploading it to a different web server?

eelixduppy

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Try this real quick:


$date = "2009-12-31";

Pollos

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

10+ Year Member



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

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

WebmasterWorld Senior Member 5+ Year Member



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

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

10+ Year Member



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

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

WebmasterWorld Senior Member 5+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

10+ Year Member



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

Featured Threads

Hot Threads This Week

Hot Threads This Month