Jump to content
xisto Community
Unholy Prayer

Display The Current Date/time With a simple PHP code

Recommended Posts

Use this code to display the current date and time.

<?php  $date = date('l dS \of F Y h:i:s A');  echo "$date";?>

"l" would display the current day of the week such as Sunday. d displays the day of the month... such as 1 and S adds the appropriate suffix(st). /of simply displays the word "of". F displays the current month with no abbreviations while Y displays the four digit year(2007). "h" displays the current hour with leading zeros if necessary(Ex. 06 for 6 o'clock). "i" displays the minute of the hour with leading zeros if necessary. "s" displays the seconds with leading zeros if necessary and finally "A" displays if it is AM or PM in uppercase format. For a full list of time formats and explanations, visit PHP.net.

Hope this is useful for you guys.

Share this post


Link to post
Share on other sites

Topic approved, but please read the rules before posting. Tutorials need to be approved by a staff member before they're visible to normal members, so please don't keep reposting if it doesn't show up right away.

Share this post


Link to post
Share on other sites

Keep in mind that the time and date that this shows will be the time and date on the server so if you are living around the server it will be the same but the actual time may differ from place to place due to timezones, etc.

Share this post


Link to post
Share on other sites

i found this on BioRust

- A = Uppercase 12hr time syntax eg. PM- a = Lowercase 12hr time syntax eg. pm- D = Day eg. Fri - d = Day eg. 03 - F = Full Text Month eg. January - G = Hours in 24 hour format without leading zeros eg. 17 - g = Hours in 12 hour format without leading zeros eg. 7 - H = Hours in 24 hour format with leading zeros eg. 17 - h = Hours in 12 hour format with leading zeros eg. 07 - i = Minutes eg. 29 - M = Month eg. Jan - m = Month eg. 01 - O = GMT time difference in hours eg. +0400 - S = Day of month suffix eg. st, nd, rd, or th. - s = Seconds eg. 28- T = Timezone setting eg. GMT, PST, EST, etc - t = Total number of days in the month eg. 28, 31, etc. - U = Seconds since the UNIX epoch eg. 1041604168- W = Week number in year eg. 42 (42nd week in the year) - w = numeric representation of the day eg. 1 = monday, 2 = tuesday, etc.- Y = Year eg. 2003 - y = Year eg. 03- z = Day of the year eg. 002 A Few ExamplesTo finish this tutorial there now follows a few examples of standard date/time strings and the values they output. I hope you enjoyed this tutorial and good luck with PHP!;)Date String Example Output date("F j, Y, g:i a"); - March 10, 2001, 5:16 pm date("m.d.y"); - 03.10.01 date("j, n, Y") - 10, 3, 2001 date("D M j G:i:s T Y"); - Sat Mar 10 15:16:08 PST 2001 date("H:i:s"); - 17:16:17 date('\i\t \i\s \t\h\e jS \d\a\y.'); - It is the 10th day.

Share this post


Link to post
Share on other sites
text changes based on the dateDisplay The Current Date/time

I am currently trying to design a website, its mainly to be used for a canteen, and I want to be able make it so the menus appear on the index page every day, because it is different for the days of the week, for example monday might be pasta with a tomato sauce, and on tuesday is say fish and chips.

I want to make it possible for the daily menu to change on its own, but I cannot find a code to use that is in CSS or HTML which are what I'm familiar with

-reply by Matt

 

Share this post


Link to post
Share on other sites
ConverstionDisplay The Current Date/time

How to convert 12 hour clock (e.G 5:30 pm) to 24 hour clock ( e.G 17:30:00) and vice versa by using php function

 

-question by Niraj Thapa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.