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.








June 12th, 2002 at 2:37 pm
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\’ );
June 26th, 2002 at 8:37 am
// 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;
}