4

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

3
  • I've improved your inline and block code formatting (may take a few minutes to be approved) so the question is clearer - but +1 for clear screenshots!
    – halfer
    Apr 7, 2012 at 10:44
  • 2
    Check your error reporting is on E_ALL and ensure there are no warnings and notices. Also, this issue might be down to timezones: midnight without a timezone may cross back to the previous day when a timezone is applied.
    – halfer
    Apr 7, 2012 at 10:46
  • 1
    As far as I know the time function doesnt take any arguments. See php.net/manual/en/function.time.php
    – Machiel
    Apr 17, 2012 at 10:11

1 Answer 1

10

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.

1
  • 1
    In addition to the answer, time() is equivalent to strotime("now")
    – MaXi32
    Jan 3, 2022 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.