Php – mktime VS time PHP4 VS PHP5

PHP

I download event calender from http://www.phpcodeworks.com/pec/installation. I am using PHP 5.3.X therefore browser said F:\xampp\htdocs\msj\functions.php so I replace :

$days = date("t", mktime(0,0,0,$month,1,$year));

with:

$days = date("t",` time(0,0,0,$month,1,$year)); 

but doing so each date goes 24 hours back as follows.

Image when using $days = date("t", mktime(0,0,0,$month,1,$year));:

enter image description here

Image when using $days = date("t", time(0,0,0,$month,1,$year));:

enter image description here

Best Answer

The mktime() function returns the time in seconds from Unix Epoch (January 1 1970 00:00:00 GMT) to the date and time provided as parameters.

The time() function retuns the time in seconds from Unix Epoch (January 1 1970 00:00:00 GMT) to the moment the function is run. There are no parameters to pass in.

So when browsing for a particular date, you will need to use mktime() instead of time(), time() will constantly return a different number every time you run it. Because of that, your calendar will change every time you view it (even if you are trying to view a particular date).

Hightlight:

mktime() - Time in seconds representing a specified date (see the documentation for the required parameters).

time() - Time in seconds representing now (there are no parameters for this function).

mktime() looks to be the appropriate function for this situation.