Weblog of Nazly Ahmed
I have been coding PHP like for almost 10 years. The date() function in PHP is a widely used function in most of my apps. The application or website I’m developing will require to associate with a date at some point. When displaying a date/time it requires to be displayed in a particular format. This will be different from one app to another. So remembering each format character is quite difficult even thought I have 10 years of experience on my back. So each an every time I head to the PHP: date() Manual to find out the format character. I have had cheat sheet wallpapers as my desktop wallpaper but I still felt the PHP Manual served me better. But finally I decided to build my own reference with commonly used character combinations with their respective output to make my life much easier (not that it was difficult before) so that other PHP developers will benefit out of this as well.
<?php #The two example outputs are based on this time #eg1: 2010-06-19 15:09:35 #eg2: 2010-06-19 08:30:59 echo date("Y-m-d"); #Output eg1: 2010-06-19 #Output eg2: 2010-06-19 echo date("n/j/y"); #Output eg1: 6/19/10 #Output eg2: 6/19/10 echo date("Y-m-d H:i:s"); #Output eg1: 2010-06-19 15:09:35 #Output eg2: 2010-06-19 08:30:59 echo date("l, jS F Y h:i a"); #Output eg1: Saturday, 19th June 2010 03:09 pm #Output eg2: Saturday, 19th June 2010 08:30 am echo date("jS M y g:i A"); #Output eg1: 19th Jun 10 3:09 PM #Output eg2: 19th Jun 10 8:30 AM echo date("D, j M Y G:i:s"); #Output eg1: Sat, 19 Jun 2010 15:09:35 #Output eg2: Sat, 19 Jun 2010 8:30:59 ?>