Okay- so I decided to dig into this and got it working for you.
BTW
Lesson one - don't question Hugh. You do not need to do the implode stuff I mentioned.
Lesson two - none of us is perfect. I changed the last line of Hugh's code from
setFormData
to
updateFormData
I created a test form and did pretty much what you wanted I think. There are a number of inter-related steps.
1) Run the code both OnBeforeProcess. If you do it OnAfterProcess the update does not work because the data is already written.
2) In your element "start_date" you must add a format for the list and form. The default format is Y-m-d so it will not show the time. I set "Y-m-d H:i" which gives you the year-month-date Hour:minute (hour is in 24 hr format). Put this in the Details, Date Format dialog under List and Form Format for the start_time element you are setting.
You'll see I have dump commands in there - they are for J!Dump. If you do not have J!Dump, it will not work.
Note - my test list is called "test_list"
---
// get start date and create a PHP date object form it
$myDate = $formModel->getElementData('test_list___test_date', true);
dump($myDate,'Mydate from FormModel');
$myDate = new DateTime($myDate);
dump($myDate,'Mydate after new DateTime');
// get the time, which will be an array with 3 entries, 0 is hours, 1 is minutes, 2 is seconds
$myTime = $formModel->getElementData('test_list___test_time', true);
dump($myTime,'MyTime from FormMOdel');
// set the time on the date object
$myDate->setTime($myTime[0],$myTime[1],$myTime[2]);
dump($myDate,'MyDate after Set Time');
// make it a formatted string ...
$myDate = $myDate->format('Y-m-d H:i:s');
dump($myDate,'Mydate after format');
// set the start date
// THis is the line I changed.
$formModel->updateFormData('test_list___start_date', $myDate, true);
-----
Here is the output from J!Dump for each of the above. (I did not expand "Methods" as it wasn't relevant.)
I entered today (8/22/2017) and a time of 3:06:10 seconds
If you do this, the record looks like this.
test date test time start_date
2017-08-22 03:06:10 2017-08-22 03:06
Notice, I did not save the seconds.
-Bob