strtotime() not working in this context, help please

257 views
Skip to first unread message

t8sh

unread,
Sep 2, 2010, 1:06:12 AM9/2/10
to Professional PHP Developers
I was almost certain that this was working before, but maybe not. I
have a dojo widget that spits out a date like this:
Thu Sep 16 2010 00:00:00 GMT-0500 (Central Daylight Time)

I want to convert that to 2010-09-16, so I tried strtotime() but it
keeps outputting the year incorrectly. It keeps doing this: 1969-09-16

the date on my server is correct

I'm not sure what's going on ... like I said, I'm 99.9% sure I didn't
change anything and this used to work. Will strtotime() not working on
the example date I gave you? Thanks in advance.

Zhang Hongyin

unread,
Sep 2, 2010, 1:16:15 AM9/2/10
to professi...@googlegroups.com
php -r "echo date('Y-m-d',strtotime('Thu Sep 16 2010 00:00:00 GMT-0500'));"
2010-09-16
php 5.3.3 on my pc, it works fine.
i guess, maybe you're using a buggy php version.

--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP

Robert Gonzalez

unread,
Sep 2, 2010, 12:18:06 PM9/2/10
to professi...@googlegroups.com
I get 2010-09-15 on my machine, PHP 5.2.6-3ubuntu4.5.

Regardless, the year seems to be working for me.

t8sh

unread,
Sep 2, 2010, 12:36:02 PM9/2/10
to Professional PHP Developers
it works this morning on my ubuntu machine, I'm getting ready to test
it on my windows machine....that's weird, the only difference was the
OS on the client side, will report back in a sec

t8sh

unread,
Sep 16, 2010, 11:21:50 PM9/16/10
to Professional PHP Developers
Hmm, this isn't working in Firefox on a Windows XP machine. Firefox
version 3.6.10 ..... but it is working in Internet Explorer. Am I
doing something wrong or is this a bug in FF?

Below are variables I'm using to make some mysql inserts/updates ...
if I use Firefox and insert into mysql the variable, $time, the date
turns out like this in the mysql table: 1969-12-31 09:00:00 .... but
if I use IE, the date turns out like this: 2010-09-22 09:00:00

$start_date = $_GET['start_date'];
$start_date = date("Y-m-d", strtotime($start_date));
$start_time = $_GET['start_time'];
$start_time = date("H:i:s", strtotime($start_time));
$time = $start_date . " " . $start_time;

Just so you know what $start_date looks like from the GET, it looks
exactly like this in Firefox: Wed Sep 22 2010 00:00:00 GMT-0500
(Central Daylight Time) and it looks like this in IE: Wed Sep 22
00:00:00 CDT 2010

So, it appears I'm having cross browser issues. I still consider
myself a PHP / MySQL novice/newb so I'm not sure what to do from here.

Thanks,

Robert Gonzalez

unread,
Sep 17, 2010, 1:25:25 AM9/17/10
to professi...@googlegroups.com
Nothing that happens in PHP will change because of your browser, especially things that actually happen on the server like a time transformation.

Jack Timmons

unread,
Sep 17, 2010, 1:50:04 AM9/17/10
to professi...@googlegroups.com
On Sep 17, 2010, at 12:25 AM, Robert Gonzalez <robert.anth...@gmail.com> wrote:

> Nothing that happens in PHP will change because of your browser, especially things that actually happen on the server like a time transformation

A common misconception. Usually things "just work" when using a different browser. This is why I have every single browser for every OS installed. Instead of writing code, I just cycle through browsers at the address I want my project to appear until it works. This is called coding on hopes and dreams.

The only reason PHP will act differently for a browser is if you tell it to. Maybe you're outputting invalid HTML and Firefox isn't being forgiving. Maybe a plugin is munging post data, replacing everything with "LOLOLOLOLOLCthuhlu".

Best plugin ever.

Sent from my eyePhone.
Love, John Quincy Doe

Sergei Kobs

unread,
Sep 17, 2010, 2:43:46 AM9/17/10
to professi...@googlegroups.com
You can use DateTime class, and ->format method:

Example:
$date = new DateTime('2000-01-01');
echo 
$date->format('Y-m-d H:i:sP')




--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP



--
Regards
Sergei
+972-54-690-67-03

Ovidiu Alexa

unread,
Sep 17, 2010, 4:14:30 AM9/17/10
to professi...@googlegroups.com
hey guys, I think that the GET differs from browser to browser. If there are spaces in the GET request there might be differences. t8sh, you must try to encode the GET with htmlentities() aka htmlspecialchars() that way you can see if there is any difference.

Second of all you should put the time in the get eg: time(strtotime('today')); and then your code should be like this:



$gd = $_GET['start_date'];//1284711077
$start_date = date("Y-m-d", $gd);
$gt = $_GET['start_time'];//1284711077
$start_time = date("H:i:s", $gt);
$time = $start_date . " " . $start_time;

Jack Timmons

unread,
Sep 17, 2010, 6:45:12 AM9/17/10
to professi...@googlegroups.com

Wait, wait.

You said you're outputting with Dojo.

Are you still doing that, or are you just echoing out the time to see
what it's like?

--
Jack Timmons
@_Codeacula

t8sh

unread,
Sep 17, 2010, 9:40:33 AM9/17/10
to Professional PHP Developers
Thanks everyone for your responses so far. Jack, yes, I am using
dojo ... so the GET is actually passed via dojo.xhrGet
Reply all
Reply to author
Forward
0 new messages