Sometimes we need to display date in our comment , post , news etc.
For that as you aware we need to store that date in our database , the format of date in database is Y M D.
But that might be possible in some cases we need to display the date in different format.
One simple way for that is explode the date which is come from database by "-" and set according to your requirement.
But what happen when we want to display date in different format like
1 jan 2011
01 january 2011
01 january 11 etc...
The solution is strtotime .
To display simple date in php
echo date("Y-m-d");
but when date comes from database at that time use :
date("j M Y ", strtotime( Here date comes form database ));
j M Y is different types of format ..More formats are display below ::
Day
Year
For that as you aware we need to store that date in our database , the format of date in database is Y M D.
But that might be possible in some cases we need to display the date in different format.
One simple way for that is explode the date which is come from database by "-" and set according to your requirement.
But what happen when we want to display date in different format like
1 jan 2011
01 january 2011
01 january 11 etc...
The solution is strtotime .
To display simple date in php
echo date("Y-m-d");
but when date comes from database at that time use :
date("j M Y ", strtotime( Here date comes form database ));
j M Y is different types of format ..More formats are display below ::
Day
- d: Day of the month with leading zeroes. Values are 01 through 31.
- j: Day of the month without leading zeroes. Values 1 through 31
- D: Day of the week abbreviations. Sun through Sat
- l: Day of the week. Values Sunday through Saturday
- w: Day of the week without leading zeroes. Values 0 through 6.
- z: Day of the year without leading zeroes. Values 0 through 365.
- m: Month number with leading zeroes. Values 01 through 12
- n: Month number without leading zeroes. Values 1 through 12
- M: Abbreviation for the month. Values Jan through Dec
- F: Normal month representation. Values January through December.
- t: The number of days in the month. Values 28 through 31.
Year
- L: 1 if it's a leap year and 0 if it isn't.
- Y: A four digit year format
- y: A two digit year format. Values 00 through 99.
Comments
Post a Comment