PHP

 Home  Computers & Internet  Web Programming PHP
What is PHP?
Echo
Comments
Variables
Constants
Data Types
number_format()
Character Strings
Mathematical Operators
Comparison Operators
Logical Operators
Joining Strings
explode()
implode()
strtolower()
strtoupper()
strlen()
ucfirst()
ucwords()
strrev()
str_replace()
str_repeat()
trim()
strip_tags()
addslashes()
stripslashes()
strpos()
strrpos()
nl2br()
isset()
unset()
empty()
POST
GET
If Statements
If Else Statements
Elseif Statements
Switch Statements
For Loops
While Loops
Do While Loops
Foreach Loops
File Create
File Open
File Read
File Write
File Delete
fgets()
file_get_contents()
Date & Time
$_SERVER
Sessions
Cookies
Arrays

HOW TO USE THE mktime() FUNCTION IN PHP

The mktime() function returns the Unix Timestamp version of a specified date. The Unix Timestamp is the number of seconds since 00:00:00 GMT on 1 January 1970. The mktime() function takes seven arguments, all of which are optional. If arguments are not specified, the values will be used from the current local date and time.

The general format of the mktime() function is as follows:

mktime(hour,minute,second,month,day,year,is_dst);

The first six arguments are self-explanatory. The seventh is whether time is daylight savings time. Takes 1 if it is, 0 if is not or -1 (default) if unknown.

Example:

echo date("M-d-Y", mktime(0, 0, 0, 12, 28, 2006));

This outputs:

Dec-28-2006

Now consider this example:

echo date("M-d-Y", mktime(0, 0, 0, 10, 34, 2006));

Note that the day argument is 34 and hence out of range - we know there is no 34 days in October or any month for that matter but let's what happens when we echo this:

This outputs:

Nov-03-2006

If you work it out, you will notice that the date echoed above is correct. mktime() automatically works it out, even out-of-range inputs, and therefore this function is useful in date calculations.

See also:

date()
time()
gmdate()
strtotime()
microtime()




Home | Privacy Policy | Terms Of Use | Contact Us