Format String to MYSQL Date format using PHP Hello Again, This is a problem I over come today. So I thought posting this will be helpful to some one who will face this problem. Thi... Powered by Blogger.
myTest Format String to MYSQL Date format using PHP Mahinda Jayasundara - 11:01 AM Hello Again, This is a problem I over come today. So I thought posting this will be helpful to some one who will face this problem. This is very simple. String coming form PHP form: 2014-11-28(string) require format for mysql: 2014-11-28(Date) So lets see how to do it. $toDate = mysql_real_escape_string($_POST ['toDate']); //coming form from from post method. $timestamp = strtotime($toDate); $myNewDate = date("Y-m-d", $timestamp); Now the mysql query. $insertQuery = "INSERT INTO `products`( `catoID`, `productTitle`, `productEndDate`, `availableProductsQTY`) VALUES( $catID, '$productName', $myNewDate', $productItems)"; $insertQuery = mysql_query($insertQuery); Hope this help you to save your valuable time. Thank you.