note 82830 added to function.date-create

From: Date: Mon, 28 Apr 2008 13:38:36 +0000
Subject: note 82830 added to function.date-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-138867@lists.php.net to get a copy of this message
Here's a way to use the DateTime object to validate user submitted date inputs: <?php class DateTimeException extends Exception { public function __construct ($message, $errornumber = NULL) { parent::__construct($message, $errornumber); } public function __toString() { return ("Error: $this->message"); } } class MyDateTime extends DateTime { public function __construct($input) { if (strtotime($input)) { parent::__construct($input); } else { $this->is_valid_date = FALSE; throw new DateTimeException("Date (" . $input . ") is incorrect"); } } public function isValidDate() { return $this->is_valid_date; } } try { $date = new DateTime("Not a date") } catch (DateTimeException $error) { echo $error; exit; } ?> Comments are very much appreciated ---- Server IP: 89.248.170.61 Probable Submitter: 82.73.100.36 ---- Manual Page -- http://www.php.net/manual/en/function.date-create.php Edit -- https://master.php.net/note/edit/82830 Del: integrated -- https://master.php.net/note/delete/82830/integrated Del: useless -- https://master.php.net/note/delete/82830/useless Del: bad code -- https://master.php.net/note/delete/82830/bad+code Del: spam -- https://master.php.net/note/delete/82830/spam Del: non-english -- https://master.php.net/note/delete/82830/non-english Del: in docs -- https://master.php.net/note/delete/82830/in+docs Del: other reasons-- https://master.php.net/note/delete/82830 Reject -- https://master.php.net/note/reject/82830 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138867) next »