1

Below is my function for inserting records to my database through HTML form. However I want my date to be typed in dd-mm-yyyy format and then be saved to my database as default yyyy-mm-dd format. I tried with strtotime and DateTime::createFromFormat(as you can see these are commented out lines) but nothing works for me.Can I get your help with it?

//---------------------------------------------------------------------
    public function addRecord(){
//---------------------------------------------------------------------
    $this->postVariablesToClassVariables() ;

    //$this->ldate= DateTime::createFromFormat('d/m/Y', $this->ldate)->format('Y-m-d');
    //$this->ldate = date('Y-m-d', strtotime($this->ldate));

    if($this->lno && $this->ldate && $this->version && $this->company &&){

    $ins = mysql_query ("INSERT INTO `mlicenses_table`(`lno`,`ldate`,`version`,`company`)
    VALUES  ('".$_POST['lno']."','".$_POST['ldate']."','".$_POST['version']."', '".$_POST['company']."')");

    $this->resetClassVariables();
    return $this->errorMessages= "New records added to database" ;

    }
    else {

    $this->errorMessages="Enter all fields required " ;
    return;
    }
    }
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
user2815059
  • 329
  • 2
  • 6
  • 12

0 Answers0