Welcome, Guest

Please login or register

TUTORIALS SUBMENU ---->

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING

Related Links

Date & Time Functions


When developing a website with PHP it is often beneficial to report server times and/or dates.  On its own this ability is quite useful, but in combination with further scripting, it allows you to account for time zones, datelines, etc, thus improving the overall user experience.  The popular forums software Vbulletin, for example, supports these functions natively.   Best of all, you can output the current server date/time with the following simple PHP instruction:

<?
echo date("D M d, Y H:i:s");
?>

This will output: Fri Jan 03, 2003 12:01:21 (or the current date/time)

To change the formatting of the date/time, you only need to change the syntax in the brackets to suit your new purpose.  For example:

- 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 Examples
To 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. *

* = Don't forget to de-limit any normal letters you want to include with the \ symbol, or else the date/time function will interpret the values as intended date/time syntax. 

- Tutorial written by Paul Dawson

Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Featured Content

Glassy Pill Buttons
Glassy Pill Buttons
- Adobe Photoshop -
Taking Tutorial Sc...
Taking Tutorial Sc...
- Adobe Photoshop -
Wrinkle Removal
Wrinkle Removal
- Adobe Photoshop -
Inset Lines
Inset Lines
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Special Options
Printer Friendly Version
Forum Threads

Competition Discussion - Brushes
Author: Man1c M0g
Posted: Feb 07th, 5:48pm
Activity: 0 replies, 54 views
 Competition - Brushes
Author: Man1c M0g
Posted: Feb 07th, 5:46pm
Activity: 0 replies, 54 views
 PM Spamming
Author: Tamlin
Posted: Feb 06th, 1:24pm
Activity: 7 replies, 116 views
Vector Clipart Bank
Author: Crapoun
Posted: Feb 06th, 11:29am
Activity: 2 replies, 93 views
How did ...
Author: MoodsR4Cattle
Posted: Feb 05th, 6:09pm
Activity: 6 replies, 27 views
Tips and trick for Texturing/Materials
Author: noorjan
Posted: Feb 05th, 4:59am
Activity: 2 replies, 111 views
 A Billion Styles - Please Help Me!!
Author: Angelz
Posted: Feb 03rd, 6:36pm
Activity: 2 replies, 135 views
101 Things you didnt know in 3DS Max ...in fact...
Author: noorjan
Posted: Jan 31st, 6:04pm
Activity: 0 replies, 161 views
Pee Wee get's an IPad
Author: MoodsR4Cattle
Posted: Jan 30th, 4:25pm
Activity: 2 replies, 163 views
Spam :: Online hotel reservations for Hotels in...
Author: kieulinh
Posted: Jan 28th, 6:39am
Activity: 0 replies, 205 views
New Design
Author: unleash
Posted: Jan 23rd, 12:39am
Activity: 3 replies, 17 views
New Design
Author: unleash
Posted: Jan 23rd, 12:39am
Activity: 27 replies, 727 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    415