Time and Date using PHP

Time and Date using PHPIn this tutorial we will learn how to display the day and/or time by using php. It's a very easy thing to do using php (theres only one line of code, thats right, only one!) so, lets get started.

Alright, brace yourself, here is the huge code we use:

<?

echo date("m-d-y") //this will display the date in mmddyy format

?>

See that wasn't so hard was it? So now whats next? Well I guess we need to know how to format the date huh? Here's a list of different charectures and what they do use to format the date:

a "am" or "pm"
A "AM" or "PM"
d Day of the month with a leading zero (01-31)
D Day of the week abrivation (Mon-Sun)
F Month (January-December)
g Hour in 12-hour format without leading 0 (1-12)
G Hour in 24-hour format without leading 0 (0-23)
h Hour in 12-hour format withleading 0 (01-12)
H Hour in 24-hour format with leading 0 (00-23)
i Minutes with leading zero (00-59)
I "1" if the date is in daylights savings time, otherwise "0"
j Day of the month without a leading zero (1-31)
l Day of the week (Monday-Sunday)
L "1" if the year is a leap year, otherwise "0"
m Month a with a leading zero (01-12)
M Month abriviation (Jan-Dec)
n Month without a leading zero (1-12)
O The difference to Greenwich time (GMT) in hours
r An RFC 822 formatted date (e.g. "Tue, 10 Apr 2005 18:34:07 +0300")
s Seconds with a leading zero (00-59)
S Suffix for the day of the month (st, nd, rd or th)
t The number of days in the current month (28-31)
T Time zone (e.g. "GMT")
U The number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
w Day of the week as a number (0-6, 0=Sunday)
W ISO-8601 week number of year, weeks starting on Monday
Y Year in yyyy format (e.g. 2003)
y Year in yy format (e.g. 03)
z Day of the year as a number (0-366)

Well thats it for the displaying time, now we can learn how to do a custom greeding by usng our time.


Related Articles

  • Date and Time
    Display the current data and time using a very small and common code.
  • Count Down
    This will let you count the number of days remaining to reach a given event : for instance days left before we reach the year 2010
  • Date Function
    Learn how people use the date function in there php coding.
  • Time and Date using PHP
    In this tutorial we will learn how to display the day and/or time by using php. Its a very easy thing to do using php (theres only one line of code, thats right, only one!) so, lets get started.
  • Last Modified, Loading Time, Preload your Images
    Last Modified, Preload your Images, Loading Time. In this tutorial you will find scripts for this topics.
  • Date of the Day in PHP
    This is a simple script but yet very useful, it consists on : catching the date, applying a given display style to it and finally showing it up. In this tutorial we are going to choose this display style: Day of the week - Month - Day of the Month - Year - : for instance today is Wednesday May 25 20...
  • Make a Calendar
    Using PHPs calendar functions, make a stylish dynamic calendar showing weekends, current month and more.
  • Last Modified and User's Screen Resolution Detection
    An easy and efficient way to write the date a file was last modified.
    We call the function filemtime() that returns an integer (the number of seconds elapsed from Jan 1st, 1970 00:00 GMT) Anyway, to make this integer viewable by human beings, we just format it using date() function.
  • Relative Dates
    In this tutorial I am going to teach you how to create your own relative date function.
  • Displaying Date and Time using PHP
    Type exactly like below in Notepad or any other HTML Editor and save it as date.php in your localhost.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.