We now have a youtube channel. Subscribe!

PHP | gmmktime() Function

PHP gmmktime() Function


Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP gmmktime() Function.

The PHP 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 have not passed any parameters to this function, it returns the current timestamp.

Syntax

Following below is the syntax to use this function -

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


Parameter Details

Sr.NoParameter & 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 Value

This built-in PHP function returns a Unix timestamp representing the given date. In case of failure, it returns the boolean value FALSE.

PHP Version

This function was first introduced as part of core PHP v 4.0 and, it works with all the later versions.

Example1

Following example illustrates the usage of the PHP gmmktime() function -

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

Output

When the above code is executed, it will produce the following result -

1589392532

Example2

Now let us invoke this built-in PHP function by passing all the needed parameters -

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

Output

When the above code is executed, it will produce the following result -

1498376205

Example3

Try the following example -

<?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);
?>

Output

When the above code is executed, it will produce the following result -

Last day in Feb 2010 is: 28nLast day in Feb 2010 is: 28


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP gmstrftime() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain