mridang_agarwal Posted October 13, 2008 Share Posted October 13, 2008 Hi Guys, I have datetime strings in the format Thu Sep 25 06:46:23 +0000 2008 and I need to use it in a MySQL insert statement. How can I convert it into a DATETIME value. For some reason I can't seem to get strtotime to work properly. I'm guessing, that this is a pretty simple question for all those PHP gurus out there. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/128223-format-datetime-into-mysql-datetime/ Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 Taken from PHP.net // Assuming today is: March 10th, 2001, 5:16:18 pm $today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm $today = date("m.d.y"); // 03.10.01 $today = date("j, n, Y"); // 10, 3, 2001 $today = date("Ymd"); // 20010310 $today = date('h-i-s, j-m-y, it is w Day z '); // 05-16-17, 10-03-01, 1631 1618 6 Fripm01 $today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day. $today = date("D M j G:i:s T Y"); // Sat Mar 10 15:16:08 MST 2001 $today = date('H:m:s \m \i\s\ \m\o\n\t\h'); // 17:03:17 m is month $today = date("H:i:s"); // 17:16:17 ?> Does this help? Quote Link to comment https://forums.phpfreaks.com/topic/128223-format-datetime-into-mysql-datetime/#findComment-664078 Share on other sites More sharing options...
mridang_agarwal Posted October 13, 2008 Author Share Posted October 13, 2008 Hi Maq, PHP.Net says: Date --> Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given. In other words, timestamp is optional and defaults to the value of time(). I'm looking to create a datetime object and not a string representation of the datetime. With so many functions listed under the Date/Time functions, I'm really lost. Thanks for the help though. Quote Link to comment https://forums.phpfreaks.com/topic/128223-format-datetime-into-mysql-datetime/#findComment-664080 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 I think you can use the new DateTime class then: $date = new DateTime($your_date); print $date->format('F j, Y'); Quote Link to comment https://forums.phpfreaks.com/topic/128223-format-datetime-into-mysql-datetime/#findComment-664085 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.