Home arrow PHP arrow Page 4 - Working with Dates and Times in PHP

Working with Dates and Times in PHP

In this article Hermawan will teach you how to work with the date and time functions in PHP in a way such that your site will not suffer from jet lag.

Author Info:
By: Hermawan Haryanto
Rating: 4 stars4 stars4 stars4 stars4 stars / 18
March 07, 2003
  1. · Working with Dates and Times in PHP
  2. · First Step
  3. · Display it to human readable date and time format
  4. · Make my own date time
  5. · Another method
  6. · My own Language

print this article

Working with Dates and Times in PHP - Make my own date time
(Page 4 of 6 )

Are you satisfied now that you can show your user for the current date and time? If you do, then don't need to read this article for more. The next step is for people who need something more.

The next function that we have to understand is mktime(). This function will make your own timestamp from a given set of variables that you pass to the function.

mktime(hour, minute, second, month, date, year);

Now, I want to know in what day my birthday was on. My birth date is July 21st 1974. I'll use the mktime function like so:

$mybirthdate = mktime(0,0,0,7,21,1974);
print date("l", $mybirthdate);

Wow, I finally found out that my birthday is on Sunday. :). Now the next case I want to know is what day is 25 days from now. Let's do it this way:

$next25day = mktime(0,0,0,date("n"),date("j")+25,date("Y"));
print date("l", $next25day);

Give attention to the variables that I passed to the mktime function. I've passed date("j")+25. It means that I want to add 25 to the current date. You can figure out what it will produce.

blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials