Possible solutions:
Use strtotime()
and date()
:
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
Source: https://stackoverflow.com/a/2487938/1415724
EDIT #2
Have a look at this:
<html>
<head>
<title>..</title>
<body>
<form action="work1.php" method="post">
Value1: <input type="text" name="date"><br>
<input type="Submit"/>
</form>
</body>
</head>
</html>
<?php
$username="root";
$password="abcdef";
$database="test_date";
$date=$_POST["date"]; // Your First Problem Post value
echo $date;
echo "i m here";
$date = date("Y/m/d", strtotime($date)); // 2nd Problem Date Format
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query = "INSERT INTO date VALUES('','$date')";
mysql_query($query);
mysql_close();
?>
Source: http://www.daniweb.com/web-development/php/threads/300356/date-stored-in-mysql-as-0000-00-00
or:
$date = date("Y-m-d", strtotime($_POST['date']));
$result = mysqli_query($link,"INSERT INTO visit_exclude_dates (date) VALUES ('{$date}')");
if(!$result) {
echo "Error: " . $link->error);
die();
}
$result->close();
$link->close();
Source: https://stackoverflow.com/a/16991316/1415724
"EDIT"
Given that the data is coming from an input form field, here is an updated answer.
If you're trying to pass your data as a "string", then use double-quotes instead.
I.e.: $string="1994-06-14";
as compared to $string='1994-06-14';
are not treated the same in PHP.
Try using the following as an example:
<input type="text" name="date_input" value="<?php echo htmlspecialchars($date); ?>" />