RE: [PHP] Date Validation

From: Date: Tue, 09 Jan 2001 18:15:20 +0000
Subject: RE: [PHP] Date Validation
Groups: php.general 
Request: Send a blank email to php-general+get-33513@lists.php.net to get a copy of this message
But if the date is out of range for the unix timestamp, it wouldn't work. Another "common" way of doing this is to make an integer using the the year, month, and day. Ie 13. november 1287 = 12871113. I made an example including a function: It will split an the date using any non-numeric data. Year has to be 4 digits. -Yurgh <? // DD MM YYYY format in input function date2int( $date ) { list( $d, $m, $y ) = split( '[^0-9]', $date ); $d = sprintf( "%02d", $d ); // Make sure the day and $m = sprintf( "%02d", $m ); // month are two digits return "$y$m$d"; } $a = "26 12 1972"; $b = "13.11.1976"; $c = "4-9-1192"; echo "$a ->".date2int( $a )."<br>"; echo "$b ->".date2int( $b )."<br>"; echo "$c ->".date2int( $c )."<br>"; ?> -----Original Message----- From: Niel Zeeman [mailto:NZeeman@lantern.co.za] Sent: 9. januar 2001 17:13 To: TV Karthick Kumar; php gen list Subject: Re: [PHP] Date Validation Hi Just a suggestion ... try using mktime to generate the timestamp for the dates and then evaluate them as such eg. for today's timestamp: $td = mktime( 0,0,0, date('m'), date('d'), date('Y') ) break up the incoming date list ($day, $month, $year) = split ('[/.-]', $datetocheck ); $id = mktime( 0,0,0,$month, $day, $year ) then you can use the evaluation '$td > $id' ----- Original Message ----- From: TV Karthick Kumar <tvkarthick@myrealbox.com> To: <php-general@lists.php.net> Sent: Tuesday, January 09, 2001 4:34 PM Subject: [PHP] Date Validation > Hi all > > I have some strange problem in Validating the date. > > I am working on some web application which is like Events in an Address > book for our customers. The requirement is whenever the Event date is passed > today's date (crosses todays date), I should be able to allow the user > delete the particular event (record) and should be deleted. > > Here's my script, it's very simple and I am not able to get the exact > results at all. Please help me. > > <? > $td=date("d/m/Y"); > echo $td; > echo "<br>"; > $id='02/02/2001'; > echo $id; > > if ($td > $id) { > echo 'todays date is greater than id'; > } > else > { > echo 'todays date is lesser than id'; > } > ?> > > -- The above script always prints the first echo statement saying that > 'todays date is greater than <$id's value>'. Why is that so ?. What's > the > other way that I can validate this date ?. > > Thanks in advance. > > ~ Karthick > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#33513) next »