Example PHP Script | Counting The Days with Date ()

This time the PHP tutorial we will discuss about the implementation date () function (learn first (function date () to display the date) and the function mktime () in PHP to know the date and month ago tomorrow.

The principle is very simple, we will use 2 pieces of PHP functions that mktime () and date (). Function mktime () function to convert a specific date into a UNIX timestamp. What's that UNIX timestamp?

UNIX time stamp is simply the number of seconds that has been running since a certain date which is used on UNIX systems, namely January 1, 1970 at 00:00:00. So, let's say January 1, 1970 0:01:00 hours, will have a UNIX timestamp 60 seconds.

Let us immediately see the pointless piece of PHP script to calculate UNIX time stamp for the last month and tomorrow even next year.

Sample code to learn PHP date () and mktime ()

<?php

$tomorrow = mktime(0, 0, 0, date("m") , date("d")+1, date("Y"));

$last_month = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));

$next_year = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);

?>

Note, for counting tomorrow, we add 1 to the date ("d") which is today's date. To calculate the last month, we reduced date ("m") which is a month today.
Previous
Next Post »