Save a date cck feild programmatically

Public

An example to see how we can save a date cck field on our node programmatically

</> CopyGet raw version
php
  1. $node = node_load($nid);
  2. // let say we have start and end date cck field and our field machine name is field_sub_start_date
  3. // we are saving start date as current date and end date as date after 1 year from current date
  4. $node->field_sub_start_date['und'][0]['value'] = date('Y-m-j');
  5. $node->field_sub_start_date['und'][0]['value2'] = date('Y-m-j',strtotime(date("Y-m-j", mktime()) . " + 365 day"));
  6. node_save($node);
  7.  
  8. // For optimisation we can better use feild api's, instead of loading the complete node.