1) If you're generating the date yourself, why not generate the date in the correct format to start with, rather than trying to convert it later?
Because that date is placed on a form that can be altered by the user.
It shows todays date in the format that everyone is used to.
So that is the format I want it to be shown in.
2) MySQL is perfectly capable of inserting the current date without you explicitly specifying it - that's what the CURDATE() function is for.
True, but - see above. The date is the publication date - can be changed so the posted item is published later rather than "today".
Does anyone know why my date_create_from_format() is not working ?
$Db_pub_date = date_create_from_format('m/d/Y',$Db_pub_date);
I could use 3 sets of substr() to cut the date up and reassemble it.
or maybe STR_TO_DATE() in the SQL query would be more efficient.
It looked to me like the date_create_from_format() was a php way of
doing the STR_TO_DATE() SQL query.
So would this be the correct way to use STR_TO_DATE() ?
$sql = "UPDATE `mypages` SET pub_date = STR_TO_DATE($Db_pub_date, '%m/%d/%Y') WHERE page_id = '$Db_page_id' ";
If anyone knows how this should be properly coded, would most appreciate the help.
Thanks.
.