Jump to content

Format date/time into MySQL DATETIME


mridang_agarwal

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/128223-format-datetime-into-mysql-datetime/
Share on other sites

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?

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.