Categorized | News

Current Date Stamp

Posted on 11 June 2002 by Demian Turner

This little function returns the current date stamp.

<?
function get_current_datestamp(){

//get the current timestamp
$currdate = gmdate(\"Ymd\");
$currday = substr($currdate,6,2);
$currmonth = substr($currdate,4,2);
$curryear = substr($currdate,0,4);
$currdate_stamp = ($curryear . \"-\" . $currmonth . \"-\" . $currday);
return $currdate_stamp;

}//end of function get_current_datestamp;

?>

Use:

$current_datestamp = get_current_datestamp()

It\’s kind of cool if you want to query a database and need a date based result – e.g. news added that day, people on holiday that day.

Bookmark and Share

2 Comments For This Post

  1. Anonymous Says:

    According the PHP Manual entry for date (which functions almost identically to gmdate): \"Unrecognized characters in the format string will be printed as-is.\"

    So just do this instead:

    $current_datestamp = gmdate( \’Y-m-d\’ );

  2. Anonymous Says:

    // get a date in two modes (one is printed \"dayname, Mon. dd, yyy\"
    // and the other internal and sortable YYYYmmddHHMMSS)
    // enter in any date in format YYMMDD to get the display date This allows the system to log
    // dates in the short-internal format and then display them in the \"printed\" format

    <?php
    function dateform($inlin) {
    global $rdate, $rdstamp, $srdstamp, $rdispdate;
    if ($inlin == \"\")
    $gdate = date(\"m/d/y H:i:s\");
    else
    $gdate = implode(\’/\’, array(substr($inlin, 2, 2), substr($inlin, 4, 2), substr($
    inlin, 0, 2)));
    $rawtime = strtotime($gdate);
    $rdate = strftime( \"%Hh%M %A %d %b\",$rawtime); // raw date format – used in debugging
    $rdstamp = strftime( \"%Y%m%d%H%M%S\",$rawtime); // long sort datestamp
    $srdstamp = strftime( \"%Y%m%d\",$rawtime); // short sort datestamp
    $rdispdate = strftime( \"%A, %d %b %Y\",$rawtime); // display date
    }
    //
    // in some cases you don\’t want the system date, but the date of the enduser timezone
    // example: users are in the US PST (-8) and the server is in hong kong
    //
    function logdate($tzone) {
    if (!gmdate(\"I\"))
    $tzone = $tzone +1;
    $secs = $tzone*(60*60);
    $rval = strftime( \"%A, %d %b %Y – %H:%M:%S\", strtotime (\"$secs seconds\", strtotime(gmdate(\"m/d/y H:i:s\" ))));// This is a timestamp used for display purposes only
    return $rval;
    }

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook