Has anyone managed to set a date field as 'all day' programmatically before? I am trying to force the value to be Y-m-d 00:00:00 - but when I view the resulting node, it actually comes out as Y-m-d 11:00am! I am trying to set the value to be 'all day' .

Edit: I've attached the function where I'm trying to achieve this. It is a page callback after my custom hook_menu() is called. The idea is, admin select dates from a custom view associated with a user, then when they hit submit, timestamps are passed to this function, creating a field collection (including these date values) - which is then attached to the node.

//This would be passed by $_POST, but I've included it here for the example.
$kw = drupal_json_decode('[{"uid":5,"nid":55,"ts":[1395493200,1395838800,1396011600]}]');

    foreach ($kw as $id => $account) {
      $uid = $account['uid'];
      $user = user_load($uid);
      $nid = $account['nid'];
      $node = node_load($nid);

      // Create the Field Collection to attach to the event node.
      // KW is a contractor
      $fc_node = entity_create('field_collection_item', array('field_name' => 'field_add_kw'));
      $fc_node->setHostEntity('node', $node);
      $fc_node->field_kw_reference[LANGUAGE_NONE][]['uid'] = $uid;
      foreach ($account['ts'] as $key => $value) {
        $fc_node->field_kw_my_dates[LANGUAGE_NONE][]['value'] = format_date($value, 'custom', 'Y-m-d 00:00:00');
      }
      $fc_node->save();
    }

cheers

Comments

joshi.rohit100’s picture

Where do you want this :- on form or on node display ?

williamsowen’s picture

Hi, I've updated the Q for more overview, cheers