NameSilo

Simple Date Output! [PHP]

Spaceship Spaceship
Watch

Ryder

Established Member
Impact
5
Every wonder how larger corporate sites have the date displayed and automatically changed everyday? Javascript? No there is a much more easier way than that!

Simple put:
PHP:
<? echo date ("l, F j, Y"); ?>

This will output:
Tuesday, December 26, 2006

More tutorials coming soon at:
http://www.netsuhi.com
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
0
•••
This requires your page extension to be .php by the way :)

edit: I should read the title aduurrr
 
0
•••
Dan: Thanks for that pointer! It is just ppl are lazy and some just rely on these type of posts :D

Thanks!
 
0
•••
DylanButler said:
This requires your page extension to be .php by the way :)

edit: I should read the title aduurrr

Not strictly ;)
 
0
•••
Just FYI, there are javascript solutions that can do the job much better.

Those javascript clocks can update the time in realtime, as its clientsided.
 
0
•••
Client side solutions are rarely is ever better. Anything that depends on a condition (such as javascript being enabled) shouldn't be relied on if it is important.
 
0
•••
suhithar i dont mean to be rude and i know you're trying to help, but if most people want to learn the date function they will just search on php.net where it has plenty of examples. Focus on writing a worthwhile script than just giving examples of lots of php functions.
 
1
•••
Matthew. said:
Client side solutions are rarely is ever better. Anything that depends on a condition (such as javascript being enabled) shouldn't be relied on if it is important.
I basically agree with it; though, PHP is mostly not realtime, and that's a big disadvantage - especially when it is about time or date functions ;)
It is also so that PHP itself is unabled to detect the timezone of the visitor (you can guess the timezone of course with IP2country databases and so of course, but thats just guessing), so it will just show the time of the server mostly - and a visitor might get confused by the time then.

PHP does can detect if javascript is enabled on the useragent of the browser. So what the best thing is to do in my opinion about showing time or date, is letting PHP see if the browser has javascript enabled (=> browscap), and if javascript is enabled, use the javascript function. Else print server time, or GMT time (gmdate()) and a clear statement of which timezone the time displayed is.
.. just a suggestion though ;)
 
0
•••
you could have a "change your timezone" link as well if you wanted. and store the user's preference in a session, or even better a cookie. I cba to go into it at the moment, but its easy enough to look up cookies and sessions on php.net as well.

Tom
 
0
•••
Appraise.net

We're social

Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back