473,396 Members | 2,013 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,396 software developers and data experts.

date function sometimes returns the wrong day

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.
Jul 17 '05 #1
3 4124
Andrew DeFaria wrote:
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?


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

Steve
Jul 17 '05 #2
Steve wrote:
Andrew DeFaria wrote:
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?
Where's the server?


In the closet! ;-)
That's the time that's being returned, not the one on the computer
running your browse.


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.
Jul 17 '05 #3
Andrew DeFaria wrote:
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?


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.

Jul 17 '05 #4

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

Similar topics

4
by: Funnyweb | last post by:
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date,...
3
by: S.W. Rasmussen | last post by:
With the risk of being accused of multi-posting I would like to draw the attention to a serious visual basic/windows issue discussed in the microsoft.public.vb.bugs newsgroup. As pointed out below...
3
by: Boris Sargos | last post by:
Hi, I need to write a function that returns a pointer on a function. Is it possible, and which is the syntax ? Thanks. Boris
4
by: Matt | last post by:
Hello. I have an Informix SQL statement that I need to run in MS SQL Server. When I try to execute it I get the following error message from Query Analyzer: Server: Msg 195, Level 15, State 10,...
5
by: Dennis M. Marks | last post by:
After reading section 15.9.1.1 the ECMAScript Language Specifications I see that the date range for the Date function is +/- 100,000,000 days from 01 Jan 1970. This is called an extrapolated...
11
by: simon | last post by:
I have the name of a day like for example 'Mon' Is there some function which returns the number of a weekDay if you have the day name or I should write the select case statements? If the day is...
4
by: Patrick McGuire | last post by:
I need to get the current date in vb .NET. In vba I always used the Date() function, and the help in .NET indicates that this function still exists, but I can't seem to find it. The Now()...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
2
by: Dave Smith | last post by:
Hi everyone again. I’m working on making my database roll with each month that changes. Below is what I have so far, and was hoping someone could help me with the rest. The error message I’m...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.