• PHP Video Tutorials

PHP gmmktime() Function


Advertisements

Definition and Usage

The gmmktime function accepts hours, minutes, seconds, month, day, year as parameters (representing a date) and returns the Unix timestamp for the given GMT date. if you haven't passed any parameters to this method, it returns the current timestamp.

Syntax

gmmktime($hour, $minute, $second, $month, $day,$ year, $is_dst)

Parameters

Sr.No Parameter & Description
1

hours(Mandatory)

This is an integer value representing the number of hours of the day, from its start.

2

minute(Mandatory)

This is an integer value representing the number of minutes of an hours, from its start.

3

seconds(Optional)

This is an integer value representing the number seconds of a minute, from its start.

4

month(Mandatory)

This is an integer value representing the month of an year, which should be between 1 and 12.

5

day(Mandatory)

This is an integer value representing the day of a date, it should be below the allowed number of days in the given month.

6

year(Mandatory)

This is an integer value representing the year of a date, it should be between 1 and 32767.

7

is_dst(Mandatory)

This parameter can be set to 1 if the time is during daylight savings time (DST), 0 if it is not, or -1 (the default)

Return Values

PHP gmmktime() function returns an Unix timestamp representing the given date. In case of a failure this function returns the boolean value false.

PHP Version

This function was first introduced in PHP Version 4.0 and, works with all the later versions.

Example

Following example demonstrates the usage of the gmmktime() function −

Live Demo
<?php
   $timestamp = gmmktime();   
   print($timestamp);
?>

This will produce following result −

1589392532

Example

Now, letus invoke the above method by passing all the required parameters −

Live Demo
<?php
   $timestamp = gmmktime(7, 36, 45, 06, 25, 2017);   
   print($timestamp);
?>

This will produce following result −

1498376205

Example

Live Demo
<?php
   $lastday = gmmktime(0, 0, 0, 3, 0, 2010);
   echo strftime("Last day in Feb 2010 is: %dn", $lastday);   
   $lastday = gmmktime(0, 0, 0, 4, -31, 2010);
   echo strftime("Last day in Feb 2010 is: %d", $lastday);
?>

This produces the following result −

Last day in Feb 2010 is: 28nLast day in Feb 2010 is: 28
php_function_reference.htm
Advertisements