Reputation: 73
So I have a form for creating scheduled dates. Title, Subject, bla bla... But then, I have a jQuery Date picker, that lets the user pick a date off a calendar. The jQuery date picker only formats for human dates I want to store them in UNIX TIME. So I have this Calendar, for the YEAR, MONTH, DAY... Then I have a standard drop down for the hour, 1:00 PM, 1:30 PM Etc...
The post print_r($_POST); looks like this,
[time] => Array
(
[0] => 5:00 PM
[1] => 1:00 PM
[2] => 8:00 PM
)
[date] => Array
(
[0] => 2014-05-08
[1] => 2014-04-04
[2] => 2014-03-28
)
I found strtotime(); for converting, human time / date into UNIX TIME, however... How do I get array [0] from time, and date to combine and be a combined string. There might be only 1 date, or 8 dates?!
Upvotes: 0
Views: 369
Reputation: 777
$count = count($_POST['date']); // assuming both date and time have same amount of values
for ($i = 0; $i < $count; $i++) {
$time = strtotime($_POST['date'][$i] . ' ' . $_POST['time'][$i]);
// do what you want with the time here
// Example: put all timestamps in an array.
$timestamps[] = $time;
}
Upvotes: 0
Reputation: 1489
You can iterate through your POST data and combine times:
foreach($_POST['date'] as $i => $date) {
$timestamp = strtotime($date.' '.$_POST['time'][$i]);
}
Upvotes: 0