redeemefy
redeemefy

Reputation: 4849

How to parse a date array in php

I have a date that I'm getting from a date picker. It is returning an array() like the following...

array(12) { 
    ["year"]=> int(2016) 
    ["month"]=> int(11) 
    ["day"]=> int(24) 
    ["hour"]=> bool(false) 
    ["minute"]=> bool(false) 
    ["second"]=> bool(false) 
    ["fraction"]=> bool(false) 
    ["warning_count"]=> int(0) 
    ["warnings"]=> array(0) { } 
    ["error_count"]=> int(0) 
    ["errors"]=> array(0) { } 
    ["is_localtime"]=> bool(false) 
}

I tried to get just the month or the year out of this array() utilizing a foreach() but no success with it. How can I iterate through this array() and extract the year or month independently?

Upvotes: 0

Views: 52

Answers (1)

Zach
Zach

Reputation: 566

You could pass the array elements through PHP mktime() and will return a UNIX Timestamp.

Doesn't look like a multidimensional array, so you shouldn't have to iterate, just access the key like:

$year = $array['year'];
// etc

Upvotes: 1

Related Questions