-2

I have to ask this question again since I couldn't get the desired Answer, But I real Want the help on this.

I have the html form which enter data into mysql DB, but in input field of date it has this format,

(mm/dd/yyyy) 

BUT I prefer to use this format when I entering date

(dd/mm/yyyy)

Can any body help to change the format from (mm/dd/yyyy) TO (dd/mm/yyyy).

Here the HTML form used to collect data

<html>
 <head>

  <body><p>Admition number:<br>
   <input type="text" class="idNum" id="idnumber"    
   onkeyup="javascript:capitalize(this.id,   
   this.value);" name="idnumber" size="20">
   <br />
   Former school:<br>
   <input type="text" id="former_school" onkeyup="javascript:capitalize(this.id,     
   this.value);"         
   name="former_school" size="20">
  <br>
   Name of Child:<br>
   <input class="fname" type="text" id="fname" onkeyup="javascript:capitalize(this.id,   
   this.value);" name="fname" size="20">
   <br />
   Admission date:<br>                                        
   <input type="date" id="add_date" placeholder="date-month-year" name="add_date"    
   size="20">
   <br />
   Nationality:<br>
   <input type="text" id="country" onkeyup="javascript:capitalize(this.id,   
   this.value);"           
   name="country" size="20">
  <br />
  Date of Birth:<br>                
  <input type="date" id="date"  placeholder="date-month-year" name="date" size="20">
  <br />
  Tribe:<br>
  <input type="text" id="tribe" onkeyup="javascript:capitalize(this.id, this.value);"      
   name="tribe" size="20">
   </body>
  </html>

This is php code for inserting data.

 <?php 
  include("Connections/conn.php")?>

  <?php
  $idnumber=mysql_real_escape_string($_POST['idnumber']);
  $insert="INSERT INTO     
  student(idnumber,former_school,fname,add_date,country,date,tribe)   
  VALUES('".$_POST["idnumber"]."','".$_POST["former_school"]."',
  '".$_POST["fname"]."','".$_POST["add_date"]."','".$_POST["country"]."',
   '".$_POST["date"]."','".$_POST["tribe"]."')";

 ?>

I use php 5.4.16

msuya
  • 1
  • 1
  • 4
  • 1
    *"I have to ask this question again since I couldn't get the desired Answer"* <- this, don't do this – Phil Jan 09 '14 at 00:16
  • Also, please read this - [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/q/12859942/283366) – Phil Jan 09 '14 at 00:22

2 Answers2

0

Use strtotime to turn a date into a unix timestamp, and then you can use the PHP date function to format that time to a string of your choice:

date('Y m d', strtotime( $_POST['add_date'] ) );
Scopey
  • 6,269
  • 1
  • 22
  • 34
0

date('m/d/Y', strtotime( $_POST['add_date'] ) );