websteve Posted August 13, 2010 Share Posted August 13, 2010 I have this Insert statement that converts the US date to the MySQL standand date format: $pur="INSERT INTO Purchasing(ID, Item, Description, Quantity, Price, Date, AMPM) VALUES ('$cust_id','$item_a','$description_a','$quantity1','$price1',STR_TO_DATE('$date', '$datefilter'),'$ampm')"; $datefilter = '%m/%d/%y'; and the $date variable is received from a HTML form and it works fine. But now, I'm trying to figure out how to do it in reverse, such as if I was to Select the date from the database and display it on the screen in US format? I can't seem to find the correct function. Any help would be appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/210653-using-str_to_date-to-get-us-date-format/ Share on other sites More sharing options...
kickstart Posted August 13, 2010 Share Posted August 13, 2010 Hi Think the function you want to use is date_format. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/210653-using-str_to_date-to-get-us-date-format/#findComment-1098896 Share on other sites More sharing options...
websteve Posted August 13, 2010 Author Share Posted August 13, 2010 Thanks. I googled data_format for additional info and I can figure it out from here. If I have any additional questions, I'll resend a message; otherwise, looks good. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/210653-using-str_to_date-to-get-us-date-format/#findComment-1098902 Share on other sites More sharing options...
otuatail Posted August 14, 2010 Share Posted August 14, 2010 you could set your table to insert the current date for you automaticaly OrderDate datetime NOT NULL DEFAULT CURDATE(), Quote Link to comment https://forums.phpfreaks.com/topic/210653-using-str_to_date-to-get-us-date-format/#findComment-1099189 Share on other sites More sharing options...
otuatail Posted August 14, 2010 Share Posted August 14, 2010 sorry that is outdated you should use OrderDate datetime NOT NULL default CURRENT_TIMESTAMP, Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/210653-using-str_to_date-to-get-us-date-format/#findComment-1099194 Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2010 Share Posted August 14, 2010 otuatail, That has nothing to do with the question and since you cannot use functions as default values for datetime data types, it's invalid as well. If the column happened to be a TIMESTAMP data type, you could use default values that are a few of the mysql function names, but that is not what the OP is doing or asking about. Quote Link to comment https://forums.phpfreaks.com/topic/210653-using-str_to_date-to-get-us-date-format/#findComment-1099200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.