Jump to content


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


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

Recommended Posts

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


Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites


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.