Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

adjust date (See related posts)

adjust date. needed if you want to substract dates
example: date is 2005-12-31, and you want to get 1 month and 2 days greater date, then you just access adjustdate('2005-12-31', $years=0,$months=1,$days=2)

function adjustdate($date,$years=0,$months=0,$days=0) {
        $year=substr($date, 0, 4);
        $month=substr($date, 5, 2);
        $day=substr($date, 8, 2);
        return date("Y-m-d", mktime(0,0,0,$month+$months,$day+$days,$year+ $years));
}

You need to create an account or log in to post comments to this site.


Related Posts