note 53327 deleted from function.date by aidan

From: Date: Sun, 31 Jul 2005 12:33:57 +0000
Subject: note 53327 deleted from function.date by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-92817@lists.php.net to get a copy of this message
Note Submitter: moazzamk at gmail dot com ---- this is a simple but helpful function i wrote for a project. it gives you the date of the previous day, for any given date. <?php class d{} function get_prev_date(&$d) { $ret = &new d(); if ($d->month == 1 && $d->day == 1) { $ret->day = 31; $ret->month = 12; $ret->year = $d->year - 1; return $ret; } if ($d->month == 3) { //for leap years and feb if ($d->day == 1 && date("L", mktime(0, 0, 0, $d->month, $d->day, $d->year)) == 1) $ret->day = 29; else if ($d->day == 1) $ret->day = 28; $ret->month = 2; $ret->year = $d->year ; return $ret; } if ($d->day == 1) { if ($d->month == 5 || $d->month == 7 || $d->month == 8 || $d->month == 10 || $d->month == 12) $ret->day = 30; else $ret->day = 31; $ret->month = $d->month - 1; $ret->year = $d->year; return $ret; } $ret->day = $d->day - 1; $ret->month = $d->month; $ret->year = $d->year; return $ret; } $d = &new d; $d->day = 1; $d->month = 3; $d->year = 2004; //2004 was a leap year $e = get_prev_date($d); print $e->year."-".$e->month."-".$e->day."\n";

« previous php.notes (#92817) next »