473,786 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

date function sometimes returns the wrong day

I have the following php code:

function Today2SQLDateti me () {
$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");
} // Today2SQLDateti me

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 4155
Andrew DeFaria wrote:
I have the following php code:

function Today2SQLDateti me () {
$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");
} // Today2SQLDateti me

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 Today2SQLDateti me () {
$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");
} // Today2SQLDateti me

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.dt d">
<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 Today2SQLDateti me () {
$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");
} // Today2SQLDateti me

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
3905
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, time and timezone, get the results returned by date() are 11 hours behind. Any ideas what is going wrong?
3
6800
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 by Norman Diamond the bug may result in loss of data when saving files with the standard common dialog control. Norman Diamond describes the problem as follows: ---------- In VB6 SP6, VB6 SP5, and possibly others, the common dialog box...
3
1141
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
16797
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, Line 4 'date' is not a recognized function name. Can anyone help me convert this informix sql statement into and MS Sql Statement? Here is the query I have:
5
2438
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 Gregorian calendar. Since the Gregorian calendar did not begin until 15 Oct 1582 what is the purpose of dates before that date? Wouldn't any computation prior to that date be meaningless or am I missing something? The reason I ask is that I have...
11
1566
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 'Mon' then result should be 2. Thank you, Simon
4
1949
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() function works just fine, but when I try to use Date(), I get an error. Am I missing a reference? What is it? Thanks, Pat
3
4414
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. Occasionally though, I need to change the "As Of Date" to some date in the past, and then when I run the queries, they're based on that date in the past. This generally works fine, but, sometimes, the date gets reset to something WAY in the past...
2
4866
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 getting is: The expression you entered has a function containing the wrong number of arguments. Jan_Loan_Amount: Sum(IIf( Between DateSerial(Year(Date()),Month(Date())-13,1) And DateSerial(Year(Date()),Month(Date())-12,0),)And Trim()>"?9?",1,0)))
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10360
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.