close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Insert and Display Date in U.S. Format (mm/dd/yy) - MySQL PHP

Thread began 4/09/2012 12:06 pm by Web Studio West | Last modified 2/02/2017 11:35 am by Web Studio West | 3665 views | 1 replies

Web Studio West

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.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...