Jump to content


Unix DateTime to MySQL Date (YYYY - MM - DD)

  • Please log in to reply
1 reply to this topic

#1 shenniko

  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 March 2006 - 03:40 PM

Hi Guys,

Need a little help..

I've got an XML page that im parsing into my MySQL Database, but the Date/Time is in Unix Date/Time...

How Can i Convert the Unix Date Time, and insert it into my MySQL Database???

Ive tried the below code, but its not working..

$sGMTMySqlString = gmdate("Y-m-d H:i:s", $availTime);
$tParsedTime = strtotime($sGMTMySqlString . " GMT");

$Query = "INSERT INTO tblresources (MyPlanet,MyName,MyType,MyCD,MyCR,MyDR,MyER,MyFL,MyHR,MyMA,MyOQ,MyPE,MySR,MyUT,MyAvail) VALUES (\"$MyPlanet\", \"$MyName\", \"$MyType\", \"$MyCD\", $MyCR, $MyDR, $MyER, $MyFL, $MyHR, $MyMA, $MyOQ, $MyPE,$MySR,$MyUT, $tParsedTime)";

And my MyAvail field in my MySQL DB is in DateTime format...

Any Ideas?

thanks in advance


#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 March 2006 - 07:44 PM

You can use the FROM_UNIXTIME() MySQL function to convert it to a valid MySQL datetime value. BTW, you have a strange HTML entity in your query string, and you might as well use single quotes for the VALUES to avoid have to do all that escaping.

Hope that helps.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users