Page 1 of 1

mktime

Posted: Fri Dec 13, 2002 4:19 am
by jayton
Hi I am newbie and I am working with the mktime() function and I have worked out how to show an image if the time difference between two dates is less than 3 days.

Where my problem lies is i want to pass a variable $date (which comes out in this format 2002-12-10) which comes from mysql database to the mktime function which will then give me a unix timestamp.

Hope that makes sense :)

Posted: Fri Dec 13, 2002 4:51 am
by f1nutter
See http://www.php.net/manual/en/function.mktime.php

mktime takes the following form :

Code: Select all

<?php
int mktime ( int hour, int minute, int second, int month, int day, int year)
?>
See http://www.mysql.com/doc/en/Date_and_ti ... tions.html

You will need to re-format the output of your database like so:

Code: Select all

SELECT
DATE_FORMAT($date, '%m') AS month,
DATE_FORMAT($date, '%d') AS day,
DATE_FORMAT($date, '%Y') AS year
FROM database;
Query the database and assign month to $month, day to $day and year to $year.

Then :

Code: Select all

<?php
$timestamp = mktime (0, 0, 0, $month, $day, $year);
?>
You can also get MySQL to output a UNIX timestamp, but not sure if it needs a time as well. Check out http://www.mysql.com/doc/en/Date_and_ti ... ml#IDX1304