SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

Mktime function to generate time stamp of any date and time


We can generate time stamp for any given date and time by using mktime function of PHP. This function is useful in doing date calculations like finding difference in two dates. We will learn how to use mktime() function along with date function to generate and check different time stamps. Here is the general syntax of mktime() function of PHP.

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


This function takes all these inputs and returns a integer having the time stamp in seconds. Time stamp in second is the gap in seconds between given time and January 1 1970 00:00:00 GMT.

Let us try to find out the time stamp of 1st January 2007, 22 hours and 30 minutes & 0 seconds. We will write this code.

$d1=mktime(22,30,0,1,1,2007);
echo $d1;
The output of the above code is 1167670800. To check the output let us use date function and use this input and find out the date.

$d1=mktime(22,30,0,1,1,2007);
echo $d1;
echo "<br>";
echo date("m/d/Y H:i:s",$d1);


As expected the out put of last line is 01/01/2007 22:30:00

Now let us find out the previous day of the above date. To do this we need not keep day as -1, the 0th day is considered as last date of the previous month. So check the output of this code. ( only the mktime function is shown here )

$d1=mktime(22,30,0,1,0,2007);


The output of this function is 12/31/2006 22:30:00 .


Further readings
PHP Date & Time functions
PHP Date Time
Validating Date: Checking if date exist
PHP Date Today
PHP yesterday and previous 7 days from today
PHP Date Format
Time stamp generator
Date selection drop down list box
mktime function to generate time stamp
Difference in Two dates by using mktime function
Finding month, weekday, day of the year etc for any date value
Breaking the date string to get month date and year using array

















Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
Date & Time
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.