note 20790 added to function.strtotime

From: Date: Tue, 16 Apr 2002 13:47:13 +0000
Subject: note 20790 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-29429@lists.php.net to get a copy of this message
If you wish to use a date without a day or without a month on it and to generate a normal timestamp to use with date() use the following: (Assuming $date is in a mysql date format (YYYY-MM-DD)) <?PHP $arDate=explode("-", $date); // Since sometimes we do not have monthes and/or days on it, we must check for their existance first $day=d; $month=M; if($arDate[1] == 00){ $arDate[1] = 01; //We must give a valid date to strtotime() otherwise it will start calculating... unset ($month); // unsetting $month so date() will not show the month. } if($arDate[2] == 00){ $arDate[2] = 01; //We must give a valid date to strtotime() otherwise it will start calculating... unset ($day); // unsetting $day so date() will not show the day. } $timeStamp=strtotime($arDate[1]."/".$arDate[2]."/".$arDate[0]); $gootdate=date("$day $month Y", $timeStamp); ?> -- http://www.php.net/manual/en/function.strtotime.php http://master.php.net/manage/user-notes.php?action=edit+20790 http://master.php.net/manage/user-notes.php?action=delete+20790 http://master.php.net/manage/user-notes.php?action=reject+20790

« previous php.notes (#29429) next »