starphp Posted May 15, 2009 Share Posted May 15, 2009 Hi, I have stored date time in a datetime datatype inside mysql database. But after formating like the following, it doesn't return the correct am/pm value. It always the return the value as am..Formating code that I used is: date("M j \a\\t g:ia", strtotime($data['last_received_time'])); So I have tried with time() and it returns the result correctly with correct am/pm value. So it is better to store the time() in MySql than the DateTime ? Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 Echo $data['last_received_time'] so that we would have a clue how to help. Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834526 Share on other sites More sharing options...
starphp Posted May 15, 2009 Author Share Posted May 15, 2009 It will be a date time value .. An example: 2009-05-14 11:46:58 Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834527 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 The date() code you posted works. If it is only giving AM results, than that means that you are only giving it an AM value. I specifically asked you to echo an actual value to eliminate the input data as the cause of the problem. Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834530 Share on other sites More sharing options...
starphp Posted May 15, 2009 Author Share Posted May 15, 2009 Sorry, I don't get what you suggested last time. Anyway, I wish to make some explanation: I have stored the datetime value in MySql like this $date = date("Y-m-d h:i:s"); INSERT INTO table (fieldName) VALUE ('$date') Then I read the value of date field from database and format the date as I mentioned above.. Then all values will be expressed on am. But if I format the $date variable at the same time while inserting the value into database, it will return the value as pm.. So I am asking abt, whether I need to store the time() value (returned by php) in database instead of the value $date to get the correct am-pm Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834531 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 The following is wrong - ("Y-m-d h:i:s"); and echoing an actual value would have told you that. Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834532 Share on other sites More sharing options...
starphp Posted May 15, 2009 Author Share Posted May 15, 2009 Yes, I understand the difference.. So it need to use the format below right ? $date = date("Y-m-d H:i:s"); Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834535 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 The way for you to answer your own question is to test if that produces the correct results. That is how programming and learning works. You have an idea and you test it to see if it proves correct or not. Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-834547 Share on other sites More sharing options...
glsbrakes Posted June 13, 2009 Share Posted June 13, 2009 I had the same type of issue. Needed to change 17:05:00 to 5:05 pm. You can store into you data base table and format is back out. or format the time to you your data base right away http://us2.php.net/manual/en/function.date.php This is the page I found to reformat the information into my data base and now when I need the info back out it looks the way I need it. Dave Link to comment https://forums.phpfreaks.com/topic/158219-how-to-store-date-time-in-mysql/#findComment-855016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.