Connecting Tech Pros Worldwide Forums | Help | Site Map

date function sometimes returns the wrong day

Andrew DeFaria
Guest
 
Posts: n/a
#1: Jul 17 '05
I have the following php code:

function Today2SQLDatetime () {
$today = date ("Y-m-d H:i:s");
print "date (\"Y-m-d H:i:s\") returned $today<br>";
return $today;
return date ("Y-m-d H:i:s");
} // Today2SQLDatetime

Most of the time this works just fine. For today, for example, it
returns "2005-02-11 xx:xx:xx". But sometimes, for some odd reason it
returns "2005-02-12 xx:xx:xx"! My theory is that since this is on my web
page and since PHP is running under Apache and since this happens every
once in a while that perhaps one of Apache's subprocess has the wrong
idea of my time zone and is actually pointed into tomorrow. Any ideas?
--
Honesty is the best policy, but insanity is a better defense.

Steve
Guest
 
Posts: n/a
#2: Jul 17 '05

re: date function sometimes returns the wrong day


Andrew DeFaria wrote:[color=blue]
> I have the following php code:
>
> function Today2SQLDatetime () {
> $today = date ("Y-m-d H:i:s");
> print "date (\"Y-m-d H:i:s\") returned $today<br>";
> return $today;
> return date ("Y-m-d H:i:s");
> } // Today2SQLDatetime
>
> Most of the time this works just fine. For today, for example, it
> returns "2005-02-11 xx:xx:xx". But sometimes, for some odd reason it
> returns "2005-02-12 xx:xx:xx"! My theory is that since this is on my web
> page and since PHP is running under Apache and since this happens every
> once in a while that perhaps one of Apache's subprocess has the wrong
> idea of my time zone and is actually pointed into tomorrow. Any ideas?[/color]

Where's the server? That's the time that's being returned, not the one
on the computer running your browse.

Steve
Andrew DeFaria
Guest
 
Posts: n/a
#3: Jul 17 '05

re: date function sometimes returns the wrong day


Steve wrote:
[color=blue]
> Andrew DeFaria wrote:
>[color=green]
>> I have the following php code:
>>
>> function Today2SQLDatetime () {
>> $today = date ("Y-m-d H:i:s");
>> print "date (\"Y-m-d H:i:s\") returned $today<br>";
>> return $today;
>> return date ("Y-m-d H:i:s");
>> } // Today2SQLDatetime
>>
>> Most of the time this works just fine. For today, for example, it
>> returns "2005-02-11 xx:xx:xx". But sometimes, for some odd reason it
>> returns "2005-02-12 xx:xx:xx"! My theory is that since this is on my
>> web page and since PHP is running under Apache and since this happens
>> every once in a while that perhaps one of Apache's subprocess has the
>> wrong idea of my time zone and is actually pointed into tomorrow. Any
>> ideas?[/color]
>
> Where's the server?[/color]

In the closet! ;-)
[color=blue]
> That's the time that's being returned, not the one on the computer
> running your browse.[/color]

I checked that. It was the correct time AFAICT. Ah ha! This might be it:
Sometimes I seem to get a date/time that is 8 hours ahead! For example,
while date returns:

Sat Feb 12 00:09:58 PST 2005

The following sometimes returns: Current date and time is: 2005-02-12
08:09:47:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<title>Test</title>
</head>
<body>
<?php
function ReturnToday () {
return date ("Y-m-d H:i:s");
} // ReturnToday

$date = ReturnToday ();
echo "Current date and time is: $date<br>";
?>

As you know Apache starts several processes to handle requests. So I
used top to see which httpd was servicing the request that was returning
the wrong date/time and kill it. There were many other httpd processes.
Refreshed the page and wham, the date and time was correct, i.e. now
displayes Current date and time is: 2005-02-12 00:14:15.

I guess this becomes a question of where does Apache get it's notion of
what timezone you are set to?
--
A mainframe: The biggest PC peripheral available.
pomasl
Guest
 
Posts: n/a
#4: Jul 17 '05

re: date function sometimes returns the wrong day


Andrew DeFaria wrote:[color=blue]
> I have the following php code:
>
> function Today2SQLDatetime () {
> $today = date ("Y-m-d H:i:s");
> print "date (\"Y-m-d H:i:s\") returned $today<br>";
> return $today;
> return date ("Y-m-d H:i:s");
> } // Today2SQLDatetime
>
> Most of the time this works just fine. For today, for example, it
> returns "2005-02-11 xx:xx:xx". But sometimes, for some odd reason it
> returns "2005-02-12 xx:xx:xx"! My theory is that since this is on my web
> page and since PHP is running under Apache and since this happens every
> once in a while that perhaps one of Apache's subprocess has the wrong
> idea of my time zone and is actually pointed into tomorrow. Any ideas?[/color]

My guess (and it's just a guess) is that the server is set to a GMT time and
then the PHP process is sometimes confusing local vs GMT time?!?!?!?

Wouldn't know why though.

CJP


--
Christopher J Pomasl Suse Linux 9.0
Senior Software Engineer Starband 360 4/68
Computer Associates SPEBSQSA, Lead/Bari, SOR
IBM Certified Specialist - DB2 UDB V6/V7 User
IBM Certified Solutions Expert - DB2 V7 Family Application Development
IBM Certified Solutions Expert - DB2 UDB Database Administration for OS/390
Always remember, you are unique...just like everyone else.

Closed Thread