Welcome Guest, Not a member yet? Register   Sign In
Getting day, month and year apart from Db
#3

I use a helper function of my own for this purpose.

Code:
function date_parts_iso($date) {

    $year = 0;
    $month = 0;
    $day = 0;

    if (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})([^\d].*)?$/', $date, $parts)) {

        if (isset($parts[1])) {
            $year = $parts[1];
        }

        if (isset($parts[2])) {
            $month = $parts[2];
        }

        if (isset($parts[3])) {
            $day = $parts[3];
        }
    }

    return array((int) $year, (int) $month, (int) $day);
}

Here it is a quick test:

Code:
list($year, $month, $day) = date_parts_iso('2018-03-09');
var_dump(compact('year', 'month', 'day'));
// array(3) { ["year"]=> int(2018) ["month"]=> int(3) ["day"]=> int(9) }
Reply


Messages In This Thread
RE: Getting day, month and year apart from Db - by ivantcholakov - 03-12-2018, 01:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB