Verifying date format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

guys this is exactly what i need but the thing doesnt work? if it is just me being retarded can u please show a example how to use it, thank you
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Which one are you trying to use and what results are you getting? (Note, this thread has not been posted to in over three years.)
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


this 1

Code: Select all

function MyCheckDate( $postedDate ) {
   if ( preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $postedDate) ) {
      list($year , $month , $day) = explode('-',$postedDate);
      return checkdate($month , $day , $year);
   } else {
      return false;
   }
}
and for calling iut useing
MyCheckDate($test);

$test = "1989-12-12"


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

use the other function instead...

Code: Select all

function MyCheckDate( $postedDate ) {
   if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $postedDate, $datebit)) {
      return checkdate($datebit[2] , $datebit[3] , $datebit[1]);
   } else {
      return false;
   }
}
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


this is correct yes ?

Code: Select all

<?
$test = '12-12-2008';
MyCheckDate( $test );
function MyCheckDate( $postedDate ) {
   if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $postedDate, $datebit)) {
      return checkdate($datebit[2] , $datebit[3] , $datebit[1]);
   } else {
      return false;
   }
}
?>
not doin anythin i must be doin sumthin wrong


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

your date: 31-12-2008 is not in the same form you're expecting: 2008-12-31
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

i changed the date but still the script does nothing at all
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It doesn't print anything, if that's what you're looking for. You must examine the return value from it to find out whether it passed or failed.
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

i cant look at the return value as the script does nothing at all, does it work for you's ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How do you know it does nothing?
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

cant see anything just a blank page and nothing in the source
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Note that I said something about that previously...
feyd wrote:It doesn't print anything, if that's what you're looking for.
You need to add some code to do the comparison.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Code: Select all

<? 
$test = '2008-12-12'; 
MyCheckDate( $test ); 
function MyCheckDate( $postedDate ) { 
   if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $postedDate, $datebit)) { 
         print_r($datebit);
      return checkdate($datebit[2] , $datebit[3] , $datebit[1]); 
   } else { 
      return false; 
   } 
} 
?>
The above code showed me it works perfectly for the above $test type of date. still what doesn't work??
Locky
Forum Newbie
Posts: 8
Joined: Thu Mar 22, 2007 7:28 pm

Post by Locky »

ahhh thank you ! i didnt realise had to do that thakns a lot, sorry i was bein so stupid :P
Post Reply