问题
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 on entering date
(dd/mm/yyyy)
Can any body help to change the format.
Here the HTML form
<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, NOTE: not the same with field above(html) becose i just mention few fields from html page.
<?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"]."')";
?>
回答1:
use this code
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
回答2:
You should be storing your dates as actual dates and not strings. You're only making your life more difficult by storing them in a non-standard format.
But if you insist on using this format, this code will work for you:
$original = DateTime::createFromFormat('m/d/Y', '04/18/1973');
$date = $original->format('d/m/Y');
回答3:
<script id="template" type="text/x-handlebars-template"> <table> <tr> <th>Posted on: </th> <td>
<?php $date = '{{posted}}';</td> </tr> </table> </script> echo date('d M Y',strtotime($date));?>
来源:https://stackoverflow.com/questions/20986251/how-to-change-date-format-on-this-html-user-form