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!)

About this user

« Newer Snippets
Older Snippets »
3 total  XML / RSS feed 

sql dates to european dates

converts sql dates to european dates and reverse.
2005-04-02 -> 02.04.2005
02.04.2005 -> 2005-04-02


function SqlToEuroDate($date) {
        $fd = substr($date, 8, 2)+0;
        $fm = substr($date, 5, 2)+0;
        $fy = substr($date, 0, 4);
        if ($fm<10) $fm = '0'.$fm;
        if ($fd<10) $fd = '0'.$fd;
        return  $newdate = $fd.'.'.$fm.'.'.$fy;
}

function EuroToSqlDate($date) {
        $fd = substr($date, 0, 2)+0;
        $fm = substr($date, 3, 2)+0;
        $fy = substr($date, 6, 4);
        if ($fm<10) $fm = '0'.$fm;
        if ($fd<10) $fd = '0'.$fd;
        return  $newdate = $fy.'-'.$fm.'-'.$fd;
}

how many days in year

calc days in year

function daysInYear($date) {
        $fd = (int)substr($date, 8, 2);
        $fm = (int)substr($date, 5, 2);
        $fy = (int)substr($date, 0, 4);
        return $days=date('z',mktime(0,0,0,$fm,$fd,$fy));
}

adjust date

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));
}
« Newer Snippets
Older Snippets »
3 total  XML / RSS feed