hammerklavier Posted January 26, 2009 Share Posted January 26, 2009 Question: I want to store a date such as "Monday January 26, 2009" I echo it in php with $today = date("l F j, Y"); Now how do I store it on MySQL ? Do I use a DATE field ? I guess not because it would be 0000-00-00 how do I save the Day too? I have $sql = "insert into table_times (idname, starttime, workdate) values ('$idname', '$starttime', '$today')"; where workdate is a DATE field And to retrive date from it back do I access to it with $example =mysql_fetch_array() ; echo $example['workdate']; Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/142530-question-about-storing-date-in-mysql/ Share on other sites More sharing options...
revraz Posted January 26, 2009 Share Posted January 26, 2009 You don't want to Store it like "Monday January 26, 2009", you want to store it as YYYY-MM-DD and then Display it as you see fit. Quote Link to comment https://forums.phpfreaks.com/topic/142530-question-about-storing-date-in-mysql/#findComment-746902 Share on other sites More sharing options...
MadTechie Posted January 26, 2009 Share Posted January 26, 2009 IMA store the date as a DATE field then when i want to view it i format it on the output.. you can store it pre-formatted but your kick yourself when you start to have problems.. output is just as easy $today = date("l F j, Y",$row['workdate']); Quote Link to comment https://forums.phpfreaks.com/topic/142530-question-about-storing-date-in-mysql/#findComment-746904 Share on other sites More sharing options...
hammerklavier Posted January 26, 2009 Author Share Posted January 26, 2009 OK So do I store it as $today = date("Y-m-d"); ?? Quote Link to comment https://forums.phpfreaks.com/topic/142530-question-about-storing-date-in-mysql/#findComment-746945 Share on other sites More sharing options...
revraz Posted January 26, 2009 Share Posted January 26, 2009 You can store it using NOW() if it's today or if another day, your example should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/142530-question-about-storing-date-in-mysql/#findComment-746957 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.