I was wondering how can I turn the following date into an array.
PHP code.
$current_date = date('Y-m-d H:i:s'); //current date
I want to put the date in a loop to compare it to other dates.
I was wondering how can I turn the following date into an array.
PHP code.
$current_date = date('Y-m-d H:i:s'); //current date
I want to put the date in a loop to compare it to other dates.
The built-in php function strptime() converts a date to an array. See the linked documentation for details about the structure of the array it produces.
I think you want to get the components of the function return into an array.
// Method one
$current_date = array(date('Y'),date('m'),date('d'),date('H'),date('i'),date('s'));
// Method two
$current_date = date('Y-m-d H:i:s'); //current date
$exploded_current_date = explode(" ", $current_date);
$date = explode("-",$exploded_current_date[0]);
$time = explode(":",$exploded_current_date[1]);
$current_date = array_merge($date,$time);
Update:
// Method three
$current_date = getdate();
/*
Returns
Array
(
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
)
*/