HOW TO: Convert Linux Date to text using PHP functions?
In PHP, purpose of date function is to format a UNIX time integer as text according to a specially encoded format string. Here you can see the process for this. We can use different parameters to get our required format.
Syntax:
string date (string $Format); string date (string $Format, int $Time);
- $Format
- A format string; the following key characters are substituted as described:
Key Description PHP Date/Time r RFC 2822: D, d M Y H:i:s O Date Year Y Year as 4 digit number y Year mod 100 as 2 digit number L 1 if a leap year, 0 if not Month F Month of the year as full name M Month of the year as three letter abbreviation m Month of the year as one or two digit number n Month of the year as two digit number Day
of
Yearz Day of the year – 1 as number Day
of
Monthd Day of the month as two digit number j Day of the month as one or two digit number jS Day of the month as one or two digit ordinal number Day
of
WeekD Day of the week as three letter abbreviation l Day of the week as full name w Day of the week – 1 as number Time Hour g Hour of the half day as one or two digit number h Hour of the half day as two digit number G Hour of the day as one or two digit number H Hour of the day as two digit number Minute i Minute of the hour as two digit number Second s Second of the minute as two digit number Millisecond u Millisecond of the second AM/PM a am or pm A AM or PM Beats B Swatch time Information t Number of days in the month TimeZone T Timezone name e Timezone abbreviatiom 5.1.0 O Offset from GMT in hundred hours P Offset from GMT in hours:minutes 5.1.3 Z Offset from GMT in seconds I 1 if Daylight Savings Time, 0 if not UNIX time U Seconds since midnight before Jan 1, 1970 5.2.2 ISO
8601Date/Time c ISO-8601 Date and time 5 Year o ISO-8601 year as 4 digit number 5.1.0 Day N ISO-8601: (((Day of the week) – 2) modulo 7) + 1 5.1.0
The return value is a string equal to the format string with substitutions from $Time (or current system time) according to the table above.
Example code:
<?php
echo "When this page was loaded,n";
echo 'It was then ', date ('r'), "n";
echo 'The currend date was ', date ('F j, Y'), "n";
echo 'The currend date was ', date ('M j, Y'), "n";
echo 'The currend date was ', date ('m/d/y'), "n";
echo 'The currend date was the ', date ('jS of M, Y'), "n";
echo 'The currend time was ', date ('g:i:s A T'), "n";
echo 'The currend time was ', date ('H:i:s O'), "n";
echo date ('Y');
date ('L')?(print ' is'):(print ' is not');
echo " a leap yearn";
?>
Output:
When this page was loaded,
It was then Sat, 26 Dec 2009 07:09:51 +0000
The currend date was December 26, 2009
The currend date was Dec 26, 2009
The currend date was 12/26/09
The currend date was the 26th of Dec, 2009
The currend time was 7:09:51 AM GMT
The currend time was 07:09:51 +0000
2009 is not a leap year
Who I Am

Zeeshan Rasool
Software Engineer - PHP
Lahore - Pakistan
zeeshan(@)99points.info
Skype: zeeshan-rasool
gTalk: zishan.rasool85
Categories
- AJAX (37)
- Codeigniter (16)
- CSS (16)
- Facebook (11)
- Joomla (1)
- JQuery (53)
- Miscellaneous (4)
- Mootools (1)
- MySQL (6)
- PHP (60)
- SEO (2)
- Technology (6)
- Tutorials (15)
- Twitter (2)
- Web Design (23)
- Web Development (57)
- WordPress (2)
Tags
Comments
- ZeeShaN on Facebook Wall Script Clone with JQuery and PHP: Personal Project BETA Version 2.0
- 20 + Fresh jQuery Image Gallery/Slider Plugins and Tutorials Worth a Look | free on JQuery Based Flipped Image Gallery with Bounce Effects
- 20 + Fresh jQuery Image Gallery/Slider Plugins and Tutorials Worth a Look | free on Fresh JQuery Image Gallery with Captions and Auto Play/Pause Rotation
- 25 Cool and Helpful jQuery Plugins/Tutorials For Your Next Project | free on jQuery Tutorial: Create jQuery and CSS based Awesome navigation.
- 25 Cool and Helpful jQuery Plugins/Tutorials For Your Next Project | free on Ajax Tutorial: How to Create Ajax Search Using PHP jQuery and MYSQL
ZeeShaN






[...] This post was mentioned on Twitter by said , 99_Points. 99_Points said: HOWTO: Convert Linux Date to text using PHP functions? http://bit.ly/cP3lcc [...]