Hello, I am new to this PHP but I am learning. I want to be able to store the time visitor come to my site to MySQL. When I use the time(), it returns a string of numbers of date and time. What I want to do is to seperate the time and the date portion of the string into two parts, and I want to reformat the time into something like 13:25, (24-hour format is fine.) so that I can store in two columns time: 13:25 and date 5/20/2007. How do I do that? Are there and predefined functions in php can do that? Thanks in advance for answering such a dumb question. MacPC.
Have a look at date(). $timestamp = time(); date('H:i', $timestamp); // 13:25 date('m/d/Y', $timestamp); // 5/20/2007 PHP:
as far i know date returns the current time if no timesstaamp is used. so MacPC,you can simply use it: $time=date('H:i'); $date=date('m/d/y'); later you just echo $time and $date where you need them
You are right, but I did it this way to show him an example on how to use date() with timestamps in general, because he wants to use timestamps from a database, and not the current one.
well he wants to store the time and date in the database where did he tell he want to use the use the timestamp from database?