logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture


dailyclick
All times in EST

Clairvoyance: 08:00 PM

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

The PHP Mktime Function

Guest Author - Diane Cipollo

The built-in PHP mktime( ) function creates a Unix timestamp for a specific date and time.

You can use PHP to easily find the current, local time and date but you do not always want to work with the current or actual time. In many cases, you will need to work with a specific, arbitrary date and time. To work with this specific time and date, you first use the built-in PHP mktime( ) function to create a Unix timestamp1 for that date and time. This timestamp is assigned to a variable that you can then make use of in your program. In the example below, I have used the day and time of my birthday this year (August 23, 2005, 10:11 am). Let's take a look at the code.

$tstamp = mktime(10, 11, 0, 8, 23, 2005);

As you can see, this function takes 6 integer arguments in the order of hour, minute, second, month, day, and year. Of course, the computer keeps time in 24 hours per day but it also handles the hours after 12 noon a little differently. From noon onward, the hours are 13 through 24. Thus, 14 would be 2 pm. The mktime( ) function can also handle values beyond the 24th hour. If I had set the hour argument to 26 in the example above, the timestamp would be for 2 am on August 24, 2005. If any of the arguments are omitted, the value for that argument is set to the local, current time on the server that is running the program. For example, if I ran a program at 4 pm and omitted the hour argument, the program would automatically use 16 for the hour argument. The example above would result in the timestamp value of 1124809860.

Now that you have the timestamp for a specific date and time and that timestamp is assigned to a variable of your choice ($tstamp in the example above), you can use this variable in many ways within your program.

1A timestamp is an integer that represents the number of seconds from the Unix Epoch (which is January 1, 1970, 00:00:00) and the date you wish to work with.




This site needs an editor - click to learn more!

Add The+PHP+Mktime+Function to Twitter Add The+PHP+Mktime+Function to Facebook Add The+PHP+Mktime+Function to MySpace Add The+PHP+Mktime+Function to Del.icio.us Digg The+PHP+Mktime+Function Add The+PHP+Mktime+Function to Yahoo My Web Add The+PHP+Mktime+Function to Google Bookmarks Add The+PHP+Mktime+Function to Stumbleupon Add The+PHP+Mktime+Function to Reddit




RSS | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor