0

I know this question has been asked before but none of the solutions is working for me, I have got a form in which the user enters the date of birth, but for reason it is set to mm/dd/yyyy and I want to change it to dd/mm/yyyy. As soon as i enter the date like 19/12/1992 it prompts invalid date format.

The code in the form is :

<label for="name">Date of Birth (mm/dd/yyyy) <font color="red"> *</font></label>
        <input type="text" name="DOB" value="<?php echo $info['DOB']; ?>" onfocus="$(this).removeClass('date required')" onchange="$(this).addClass('date required')" required />

And the code in the function after POST is:

$DOB = mysql_real_escape_string($_POST['DOB']);
Rajeesh Menoth
  • 1,704
  • 3
  • 17
  • 33
user3297381
  • 11
  • 1
  • 6

3 Answers3

1

EDITED: use this:

1)

 $DOB = mysql_real_escape_string($_POST['DOB']);
           $newDate = date("d/m/Y", strtotime($DOB));

OR

2) $newDate = DateTime::createFromFormat('m/d/Y', $DOB)->format('d/m/Y');

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
0

You could use strtotime:

$oldDOB = mysql_real_escape_string($_POST['DOB']);
$DOB = date("d/m/Y", strtotime($oldDOB));
JoelP
  • 439
  • 1
  • 3
  • 13
0

Like they all said do this

 $DOB = mysql_real_escape_string($_POST['DOB']);
 $newDate = date("d/m/Y", strtotime($DOB));

Then at the other side where you are either inserting or updating the database change the date back to mysql standard format like this:

$DOB_DB = mysql_real_escape_string($_POST['DOB']);
$DOB_DB = date("m/d/Y", strtotime($DOB_DB));