mktime() calculates the UNIX timestamp for the time and date given by its parameters. All parameters are optional; if a parameter isn't specified, the current time is used for that parameter. However, keep in mind that arguments can only be left off in order from right to left (for example, you can't leave out day without first leaving out year and is_dst ).
You can give invalid values to mktime() , and it will automatically calculate the correct value. For instance, if you specify the date April 32, mktime() will calculate it as May 2.
mktime() accepts the year parameter as either a two-digit or four-digit integer. However, any year value given must fall within the range supported by the system on which PHP is running. Most current systems use a 32-bit integer to store the date and time, meaning that mktime() will only work on dates within the range 1970-2037 (inclusive). Furthermore, if a two-digit value is given, values from 0 through 69 will be interpreted as the corresponding years from 2000 through 2069, while values from 70 through 99 will be interpreted as the corresponding years from 1970 through 1999.
is_dst tells mktime() whether Daylight Saving Time should be taken into account. There are three valid values: 1 means yes, 0 means no, and-1 means unknown. The default is-1.
Note that 0 can have different meanings, depending on the parameter for which you use it:
This list has some interesting implications. For instance, it's always easy to find out what the last day of February is for any given year - simply ask for the 0th day of March:
To follow the logic, note that 0 for year gives 2000, while 0 for month gives the last month of the preceding year, 1999. The 1 for day means to give the first day of that month, so you wind up with December 1, 1999.
However, PHP's implementation of mktime() will return -1 if you specify 0 for each of month , day , and year , not November 30, 1999, as you might expect.
/* When tested at 22:21 on April 19 2001, * the following code produced this output: * 22:21:32 Thursday, Apr 19 2001 * 22:21:32 Thursday, Apr 19 2001 * 14:00:00 Wednesday, May 2 2001 * 14:00:00 Monday, Apr 30 1973 * 14:00:00 Wednesday, Apr 30 2025 */ /* Print the current date and time. */ echo strftime("%X %A, %b %e %Y\n", mktime()); /* The above is the same as using time() for this purpose. */ echo strftime("%X %A, %b %e %Y\n", time()); /* Print the time and date at 2 PM April 32. * mktime() will compensate for the fact that there is no April 32. */ echo strftime("%X %A, %b %e %Y\n", mktime(14, 0, 0, 4, 32)); /* The '73' year value produces a result year of 1973. */ echo strftime("%X %A, %b %e %Y\n", mktime(14, 0, 0, 4, 30, 73)); /* The '25' year value produces a result year of 2025. */ echo strftime("%X %A, %b %e %Y\n", mktime(14, 0, 0, 4, 30, 25));
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.