Insert and Display Date in U.S. Format (mm/dd/yy) - MySQL PHP
If you have a form field for entering a date in MM/DD/YY format but need to insert it into a MySQL database (which is YYYY/MM/DD format), place this code at the very top of your page to convert the date format so it will insert correctly. My form field name is "mydate" so change that to your field name. If you're using the WebAssist DatePicker, the field ID will be called something like: datepicker_1. Don't change or use the field ID. Use the field name.
<?php
if(isset($_POST['mydate']) && $_POST['mydate'] != "") {
$_POST['mydate'] = date("Y-m-d", strtotime($_POST['mydate']));
}
?>
If you're retrieving the date from a MySQL database and need to display in MM/DD/YY format, use this code on your page where you want the date to appear:
<?php echo date("m/d/y", strtotime($row_MyRecordset['mydate'])); ?>
Of course, change the recordset name and field name to yours. You can also use the above code to populate the value of a form field if you're doing an update page.