Categories
PHP Snippets

Calculating This Day Last Year in PHP

Have you ever wanted to know what the date was last year on this day?

Example: You want to compare sales from Wednesday of this year to the same Wednesday of last year. There is a very simple solution in PHP.

[code]
function ThisDateLastYear($date_in) {
// date_in = input date in form of YYYY-MM-DD
$days = 364;
return date(‘Y-m-d’, strtotime(“-364 days”, mktime(0,0,0,$m,$d,$y)));
}
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *