Skip to main content

Posts

Showing posts from March, 2012

Date formats in php

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 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.