Jump to content

Archived

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

shenniko

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

[code]
$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)";
[/code]

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

Any Ideas?

thanks in advance

Shenn

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.