1

I want to save multi Date value in a node programmatically.

$node->field_event_date['und'][0]['value'] =?;
$node->field_event_date['und'][0]['value2'] =?;

getting the below value after print the form_state

[field_event_date] => Array
                        (
                            [und] => Array
                                (
                                    [0] => Array
                                        (
                                            [show_todate] => 1
                                            [value] => Array
                                                (
                                                    [date] => 07/02/2015
                                                    [time] => 10:30AM
                                                )

                                            [value2] => Array
                                                (
                                                    [date] => 07/02/2015
                                                    [time] => 12:30PM
                                                )

                                        )

                                )

                        )

Getting error

$node->field_event_date['und'][0]['value'] = 
    $form_state['input']['line_item_fields']['field_event_date']['und'][0]['value']['date'];

$node->field_event_date['und'][0]['value2'] = $form_state['input']['line_item_fields']['field_event_date']['und'][0]['value2']['date'];

But i need both date and time. I think i need to combine date and time and convert it into time stamp to save but do not understand how to combine and convert.

1 Answer 1

1

If converting the two is your problem following may help you

foreach ($form_state['values']['field_event_date']['und'] as $key=> $value) {
  $node->field_event_date['und'][$key]['value'] = strtotime($form_state['values']['field_event_date']['und'][$key]['value']['date'] . ' ' . $form_state['values']['field_event_date']['und'][$key]['value']['time'])
}

strtotime() should be good enough.

I am assuming you are doing node_save() some where.

1
  • glad it helped you :)
    – arpitr
    Jul 3, 2015 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.