bobby317 Posted June 17, 2010 Share Posted June 17, 2010 What I am trying to do is use these two Mysql functions to switch my dates back and forth for my event calendar I am creating using Mysql and php. I am trying to learn how to do this and this is the website I am getting my info from so you know. http://www.richardlord.net/blog/date-in-php-and-mysql Now I know you can use the FROM_UNIXTIME function to update a table like this: $query = "UPDATE table SET datetimefield = FROM_UNIXTIME($phodate)"; p My question is how do I work the FROM_UNIXTIME($phpdate) function into an INSERT into statement? This is the query I am trying to work these functions into. $query = "INSERT INTO events (eventID, date, startTime, endTime, eventName, description) VALUES (0, '$date', '$fStartTime', '$fEndTime', '$eventName', '$description')"; Thanks for all the help please explain so I may learn. Quote Link to comment https://forums.phpfreaks.com/topic/205065-using-from_unixtime-and-unix_timestamp-in-and-insert-into-statement/ Share on other sites More sharing options...
bobby317 Posted June 17, 2010 Author Share Posted June 17, 2010 sorry had the link to the site wrong. http://www.richardlord.net/blog/dates-in-php-and-mysql Quote Link to comment https://forums.phpfreaks.com/topic/205065-using-from_unixtime-and-unix_timestamp-in-and-insert-into-statement/#findComment-1073484 Share on other sites More sharing options...
fenway Posted June 17, 2010 Share Posted June 17, 2010 Sorry, I don't follow. Quote Link to comment https://forums.phpfreaks.com/topic/205065-using-from_unixtime-and-unix_timestamp-in-and-insert-into-statement/#findComment-1073589 Share on other sites More sharing options...
bobby317 Posted June 17, 2010 Author Share Posted June 17, 2010 Ok I don't know what else to explain. Mysql has two function: 1. FROM_UNIXTIME() This function from the best I can tell converts a PHP timestamp to a DATETIME. 2. UNIX_TIMESTAMP() This function from the best I can tell converts DATETIME to a php timestamp. I am creating an event calendar that I would like to use these function to convert my php dates which are in php timestamp form into the DATETIME form to store into my database. Wright now this is the query I am using to insert my data into the data base. $query = "INSERT INTO events (eventID, date, startTime, endTime, eventName, description) VALUES (0, '$date', '$fStartTime', '$fEndTime', '$eventName', '$description')"; I would like to know how I would write this query to set FROM_UNIXTIME($date) so that Mysql will turn my $date varable which is a phptimestamp into the DATETIME format and store it in the data base. Then I need one for retreving the DATETIME format back from the database and convert it back to a phptimestam with UNIX_TIMESTAMP() function. I hope I explained it better sorry for the lack of ability to explain my self. And thanks for everything Quote Link to comment https://forums.phpfreaks.com/topic/205065-using-from_unixtime-and-unix_timestamp-in-and-insert-into-statement/#findComment-1073606 Share on other sites More sharing options...
Mchl Posted June 17, 2010 Share Posted June 17, 2010 $query = "INSERT INTO events (eventID, date, startTime, endTime, eventName, description) VALUES (0, FROM_UNIXTIME($date), FROM_UNIXTIME($fStartTime), FROM_UNIXTIME($fEndTime), '$eventName', '$description')"; Quote Link to comment https://forums.phpfreaks.com/topic/205065-using-from_unixtime-and-unix_timestamp-in-and-insert-into-statement/#findComment-1073610 Share on other sites More sharing options...
bobby317 Posted June 17, 2010 Author Share Posted June 17, 2010 Thanks for everything!! Quote Link to comment https://forums.phpfreaks.com/topic/205065-using-from_unixtime-and-unix_timestamp-in-and-insert-into-statement/#findComment-1073623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.