Here is a quickie to get the date prior to another date. You can make it one, two, 3 days prior. Doesn’t really matter. PHP’s mktime() function self corrects when you put in a day and subtract the number from it.
Yes. Even if it 2010-01-01 it will go return 2009-12-31.
function currWeek()
/**
* Returns the date one day before the one entered, regardless of year or day of month.
* Y-m-d
* @return $dateBefore
* @param object $mydate
*/
function getDayBefore($mydate){
$mydate = explode("-", $mydate);
$myyear = $mydate[0];
$mymonth = $mydate[1];
$myday = $mydate[2];
$dateBefore = mktime(0,0,0, $mymonth, $myday-1, $myyear);
$dateBefore = date('Y-m-d',$dateBefore);
return $dateBefore;
}
UPDATE!! A plugin is now available for this tutorial that includes more features read more...
How often do you work with tables? I work with them quite a bit and styling t read more...
When running a site with a boat load of javascript, you may want to run a script read more...
Download Plugin THEMES: theme-lighttheme-dark<link href="{{ path to js read more...
Greetings All! Since everyone was digging the Star Comment Rating I decided that read more...
Hi Eli,
You can always use PHP’s strtotime() function, which converts a string into a timestamp, and you can also be less concerned about what format the date comes in.
function daybefore($date){
return date(‘Y-m-d’, strtotime($date . ” -1 day”));
}
Thanks! I’ll have to check that out!