Forum Moderators: coopster

Message Too Old, No Replies

How to use mktime function?

         

dbarasuk

9:25 pm on May 10, 2008 (gmt 0)

10+ Year Member



Hello!
I have a script below:
$date=date( 'Y-m-d H:i:s', mktime($hour, $minutes, $seconds, $month, $day, $year) );
// prepare an SQL query
$sql = "INSERT INTO articles(name, email, subject, message, created )
VALUES('$y_name', '$email', '$subject', '$message', '$date')";

The goal of the script is to insert in a mysql table different values submitted with $_POST method. The 'Created' field is designed to hold the date and time whenever a message is sent to database.

However that field receives the date part and NEVER the time part as intended in the script above.

Which function should I use so that the field shows also the time at which the message was inserted(not only the date part)?

Note: The arguments of the mktime functions are not mentionned here as it's not necessary to show them.

Thanks.

MattAU

9:47 pm on May 10, 2008 (gmt 0)

10+ Year Member



That looks fine to me.

I think it's most likely that the database field is the 'date' type, not the 'datetime' type that you need to store the time as well.

Keep in mind that you can also use the following syntax (depending on the dataebase) to add the current date/time for you:

$sql = "INSERT INTO articles(name, email, subject, message, created )
VALUES('$y_name', '$email', '$subject', '$message', now())";

dbarasuk

10:35 am on May 11, 2008 (gmt 0)

10+ Year Member



Dear mattAU,
thanks, it's right changing the data type from date to datetime.

But note that the now() function you'll talking about doesn't exists in the php function list.

be blessed!

MattAU

10:44 am on May 11, 2008 (gmt 0)

10+ Year Member



now() is a mysql function, not a php one... :)