note 105611 added to function.date

From: Date: Wed, 31 Aug 2011 15:58:23 +0000
Subject: note 105611 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-182867@lists.php.net to get a copy of this message
This is my solution if you are looking for a function that checks if the date is valid and also check if the date is in the future (for example passing only the month and year for a credit card verification). I grabbed parts of this code from a different site or comment that I cannot find now: <?php function valid_date($year, $month=0, $day=0, $future_only = false){ if(!$this->numeric($year) || !$this->numeric($month) || !$this->numeric($day)) return false; $skip_check_day = false; $skip_check_month = false; if($year>99){ $year = intval(substr($year,-2)); } if($month==0){ $month = strftime('%m'); $skip_check_month = true; } if($day==0){ $day = strftime('%d'); $skip_check_day = true; $last_day_month = date('t',mktime(0,0,1, $month, 1, $year)); if($day>$last_day_month){ $day = $last_day_month; } } $mktime = mktime(23,59,59,$month, $day, $year); $correct_day = ($skip_check_day || intval(strftime('%d',$mktime))==intval($day)); $correct_month = ($skip_check_month || intval(strftime('%m',$mktime))==intval($month)); $correct_year = (intval(strftime('%y',$mktime))==intval($year)); if(!$correct_day || !$correct_month || !$correct_year){ return false; } if($future_only && $mktime<time()) return false; return true; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 70.61.72.22 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/105611 Del: integrated -- https://master.php.net/note/delete/105611/integrated Del: useless -- https://master.php.net/note/delete/105611/useless Del: bad code -- https://master.php.net/note/delete/105611/bad+code Del: spam -- https://master.php.net/note/delete/105611/spam Del: non-english -- https://master.php.net/note/delete/105611/non-english Del: in docs -- https://master.php.net/note/delete/105611/in+docs Del: other reasons-- https://master.php.net/note/delete/105611 Reject -- https://master.php.net/note/reject/105611 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#182867) next »