Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/4840-unix-datetime-to-mysql-date-yyyy-mm-dd/
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.
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.