Jump to content

Using FROM_UNIXTIME and UNIX_TIMESTAMP in and INSERT into statement


Recommended Posts

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.

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

$query = "INSERT INTO events (eventID, date, startTime, endTime, eventName, description) VALUES (0, FROM_UNIXTIME($date), FROM_UNIXTIME($fStartTime), FROM_UNIXTIME($fEndTime), '$eventName', '$description')";

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.