LinkShare  Referral  Program

New

Advertise ad Here
learn more
            PHP > date manipulation functions>today function
Added on   06.09.09
Clicks     1388
Rating:   5.00   out of 5 from   2   raters      
         rate this page   
 Not rated yet.Be the first one to vote!!

iBuyOfficesupply.com Inc. There is not Comments for this Article,Be the first one
Ask any relevant question in the Comments or leave your valuable feed-back

printer  Print version of this article

star  Add it to your favourite!

mail email this page to a frend
LinkShare  Referral  Program

Date and time manipulation functions



 Today function




 

 

    In PHP, to have today's date you can use the built in function date() or the following function I wrote, to make sure to add the correct time zone with the day light saving.



    We assume that all the functions will be saved in a file called php_functions.php

    <?php
    function today($time_zone,$format)
    {
    $zone=3600*$time_zone;
    $today=gmdate($format, time() + $zone);
    return $today;
    }
    ?>

    Explaining the above function is quite simple, as you can see ,it has 2 parameters,$time_zone is your time zone that will be added to the GMT time plus day light saving in summer if you have it, $format is where you put the format you want the date to appear in your page, for complete formatting details, visit the PHP manual page.

    $zone=3600*$time_zone; The variable $zone will hold the result of your time zone by 3600 which are the seconds in 1 hour

    $today will hold  the formatted date resulting by the return of the built in PHP function gmdate

    See the example below to use the function

    <?php
    include 'php_functions.php';

    $time_zone=8;
    $format='d-m-Y';
    $today=today($time_zone,$format);
    echo $today;
    ?>

     

    Try the example below

     Your time zone  
     The format you want  
     Today date is