DISPLAYING CURRENT TIME?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
danielwalters6
Forum Commoner
Posts: 31
Joined: Fri May 11, 2007 1:17 pm
Location: Cambridge, England, UK

DISPLAYING CURRENT TIME?

Post 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
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

date()

Wayne
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

date('m-d-Y', time());
;)
User avatar
danielwalters6
Forum Commoner
Posts: 31
Joined: Fri May 11, 2007 1:17 pm
Location: Cambridge, England, UK

Thankyou - Works a Treat!

Post by danielwalters6 »

Thankyou - Works a treat!
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
danielwalters6
Forum Commoner
Posts: 31
Joined: Fri May 11, 2007 1:17 pm
Location: Cambridge, England, UK

:)

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Show your code.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
danielwalters6
Forum Commoner
Posts: 31
Joined: Fri May 11, 2007 1:17 pm
Location: Cambridge, England, UK

My Code

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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).
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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(); ?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

:oops:, I was beside myself when I wrote that
User avatar
danielwalters6
Forum Commoner
Posts: 31
Joined: Fri May 11, 2007 1:17 pm
Location: Cambridge, England, UK

Still doesn't work....

Post by danielwalters6 »

Still doesn't work :(
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

what did you try?
User avatar
danielwalters6
Forum Commoner
Posts: 31
Joined: Fri May 11, 2007 1:17 pm
Location: Cambridge, England, UK

Post by danielwalters6 »

Unsure why it didn't work - it is now.
Post Reply