SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: PHP checkdate()

  1. #1
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP checkdate()

    Hi All,

    I'm trying to build the "checkdate" function into this piece of code but it seems to output the "invalid date" text on the page all the time (before I've even submitted the form) - Can someone tell me the right place to put it and the correct syntax to use please?

    Here is the code that is used to build the form:

    PHP Code:
    function duedate_datechooser($name,$value="")
    {
        
    $months=array('','January','February','March','April','May','June','July','August',
        
    'September','October','November','December');
        
        if(empty(
    $value)) $value=date("Y-m-d");
        
        
    $parts=explode("-",$value);
        
        
    $day=$parts[2]+0;
        
    $month=$parts[1]+0;
        
    $year=$parts[0];
        
        
    $chooser="";
        
        
    $chooser.="<select name=".$name."day>";
        for(
    $i=1;$i<=31;$i++)
        {
            if(
    $i==$day$selected='selected';
            else 
    $selected='';
            
    $chooser.="<option $selected>$i</option>";
        }
        
    $chooser.="</select> / ";
        
            
    $chooser.="<select name=".$name."month>";
        for(
    $i=1;$i<=12;$i++)
        {
            if(
    $i==$month$selected='selected';
            else 
    $selected='';
            
    $chooser.="<option $selected value=$i>$months[$i]</option>";
        }
        
    $chooser.="</select> / ";

        
        
    $chooser.="<select name=".$name."year>";
        for(
    $i=(date("Y")-1);$i<=2050;$i++)
        {
            if(
    $i==$year$selected='selected';
            else 
    $selected='';
            
    $chooser.="<option $selected>$i</option>";
        }
        
    $chooser.="</select> ";    
        
        return 
    $chooser;

    I need to check the date is valid when the form is submitted.

    Thanks,

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I see no "invalid date" in that piece of code? Maybe it's in the code that calls this function?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •