Miscellaneous
  Home arrow Miscellaneous arrow Page 3 - Working with dates and times in PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Working with dates and times in PHP
By: Hermawan Haryanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-11-12

    Table of Contents:
  • Working with dates and times in PHP
  • Human Readable Formats
  • Making your own date and time
  • My own Language

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with dates and times in PHP - Making your own date and time


    (Page 3 of 4 )

    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.

    int mktime ( int hour, int minute, int second, 
         int month, int day, int year [, int is_dst])

    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:

    <?php
    $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:

    <?php
    $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.

    Another method

    This is another method to access the current date or the given timestamp that you’ve produced by your own script. The method, or you can call it function, is getdate(). This function will produce an associative array containing the date information. The array key is:

    "seconds" - seconds 
    "minutes" - minutes 
    "hours" - hours 
    "mday" - day of the month 
    "wday" - day of the week, numeric: from 0 as Sunday up to 6 as Saturday 
    "mon" - month, numeric 
    "year" - year, numeric 
    "yday" - day of the year, numeric; i.e. "299"
    "weekday" - day of the week, textual, full; i.e. "Friday" 
    "month" - month, textual, full; i.e. "January"

    Example Usage:

    <?php
    $today 
    getdate();
    print 
    $today["month"// it will print the month of current date
    print $today["weekday"// it will print the day of current date
    ?>

    More Miscellaneous Articles
    More By Hermawan Haryanto


       · get me date function of today's in the php language
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT