note 110112 added to function.date-format

From: Date: Thu, 20 Sep 2012 15:20:07 +0000
Subject: note 110112 added to function.date-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-190935@lists.php.net to get a copy of this message
I wanted a simple php function which can give me date in whatever format I want so here is the one function format_date($date, $type, $seperator="-") { if($date) { $day = date("j", strtotime($date)); $month = date("n", strtotime($date)); $year = date("Y", strtotime($date)); $hour = date("H", strtotime($date)); $min = date("i", strtotime($date)); $sec = date("s", strtotime($date)); switch($type) { case 0: $date = date("Y".$seperator."m".$seperator."d",mktime($hour, $min, $sec, $month, $day, $year)); break; case 1: $date = date("D, F j, Y",mktime($hour, $min, $sec, $month, $day, $year)); break; case 2: $date = date("d".$seperator."m".$seperator."Y",mktime($hour, $min, $sec, $month, $day, $year)); break; case 3: $date = date("d".$seperator."M".$seperator."Y",mktime($hour, $min, $sec, $month, $day, $year)); break; case 4: $date = date("d".$seperator."M".$seperator."Y h:i A",mktime($hour, $min, $sec, $month, $day, $year)); break; case 5: $date = date("m".$seperator."d".$seperator."Y",mktime($hour, $min, $sec, $month, $day, $year)); break; case 6: $date = date("M",mktime($hour, $min, $sec, $month, $day, $year)); break; case 7: $date = date("Y",mktime($hour, $min, $sec, $month, $day, $year)); break; case 8: $date = date("j",mktime($hour, $min, $sec, $month, $day, $year)); break; case 9: $date = date("n",mktime($hour, $min, $sec, $month, $day, $year)); break; case 10: $diff = abs(strtotime($date) - strtotime(date("Y-m-d h:i:s"))); $years = floor($diff / (365*60*60*24)); $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24)); $date = $years ." years, ".$months. " months, ". $days. "days"; } } return($date); } ---- Server IP: 59.162.86.8 Probable Submitter: 219.91.212.246 ---- Manual Page -- http://www.php.net/manual/en/function.date-format.php Edit -- https://master.php.net/note/edit/110112 Del: integrated -- https://master.php.net/note/delete/110112/integrated Del: useless -- https://master.php.net/note/delete/110112/useless Del: bad code -- https://master.php.net/note/delete/110112/bad+code Del: spam -- https://master.php.net/note/delete/110112/spam Del: non-english -- https://master.php.net/note/delete/110112/non-english Del: in docs -- https://master.php.net/note/delete/110112/in+docs Del: other reasons-- https://master.php.net/note/delete/110112 Reject -- https://master.php.net/note/reject/110112 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190935) next »