Page 1 of 1
DISPLAYING CURRENT TIME?
Posted: Fri May 11, 2007 1:22 pm
by danielwalters6
PHP Newbie here...
Is there a TIME function within PHP or am I barking up the completely wrong tree?
I would like to display within a html file (I normally just rename the extension to .php to get it to run on my server)
"String Relevent To Time Of Day, ie. Goodmorning - "[TIMEOFDAYHERE]
Could anyone help me... point me in the right direction?
TIA for any help
Dan
Posted: Fri May 11, 2007 1:26 pm
by guitarlvr
Posted: Fri May 11, 2007 1:26 pm
by John Cartwright
Thankyou - Works a Treat!
Posted: Fri May 11, 2007 1:28 pm
by danielwalters6
Thankyou - Works a treat!
Posted: Fri May 11, 2007 1:44 pm
by Weirdan
but [s]beer[/s]bear in mind that time() returns server's local time, which may not be the same as the user's time. For example its a night here (9:44 PM), but it's still afternoon in Toronto.
:)
Posted: Fri May 11, 2007 1:49 pm
by danielwalters6
Thankyou, you're right it's only 19.46 here!
However our site is a UK "directory" so our UK Webservers have 99.99% of the user's time zones set okay.
It was working, i think, but it's now not displaying anything on the page where the php code should be.
As a total beginner how sould i implement it in my pages?
TIA,
DAN
Posted: Fri May 11, 2007 1:50 pm
by John Cartwright
Show your code.
Posted: Fri May 11, 2007 1:54 pm
by Weirdan
It was working, i think, but it's now not displaying anything on the page where the php code should be.
Post your code. Also it's good idea to add the following lines at the beginning of your script:
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', true);
while you're debugging your script. But don't forget to remove then once you finished.
My Code
Posted: Fri May 11, 2007 2:01 pm
by danielwalters6
It's a html page, which I added the snippet of php, and then renamed from index.html to index.php otherwise my server won't run php on the page.
The code that's relevent is as follows:
<a href="./webteam">Website Team</a> - <?php echo "date()" ?>
I'm calling it in the wrong way though?
Posted: Fri May 11, 2007 2:05 pm
by John Cartwright
Firstly, do not quote function names as it will result in a parse error. Secondly, I suggest you read the manual on the
datefunction to understand how it works, or use my example (I recommend the former).
Posted: Fri May 11, 2007 2:16 pm
by Weirdan
Firstly, do not quote function names as it will result in a parse error.
Why would it generate a parse error? The function name will be echoed and that's it.
danielwalters6 you missed the semicolon after the date() function call:
Code: Select all
<a href="./webteam">Website Team</a> - <?php echo date(); ?>
Posted: Fri May 11, 2007 2:17 pm
by John Cartwright

, I was beside myself when I wrote that
Still doesn't work....
Posted: Fri May 11, 2007 2:44 pm
by danielwalters6
Still doesn't work

Posted: Fri May 11, 2007 3:07 pm
by John Cartwright
what did you try?
Posted: Fri May 11, 2007 3:10 pm
by danielwalters6
Unsure why it didn't work - it is now.