Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.