Guest User

Untitled

a guest
Jun 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. hook_form_alter(&$form, &$form_state, $form_id) {
  2.  
  3. // http://drupal.org/node/1455576 - Date
  4. $form['field_date'][LANGUAGE_NONE][0]['value'] = time();
  5.  
  6. // http://drupal.org/node/1455576 - Date (ISO Format)
  7. $form['field_date_iso_format'][LANGUAGE_NONE][0]['value'] = time();
  8.  
  9. // http://drupal.org/node/1455576 - Date (Unix Timestamp)
  10. $form['field_date_unix_timestamp'][LANGUAGE_NONE][0]['value'] =time();
  11. }
  12.  
  13. $node->field_date[LANGUAGE_NONE][0] = array(
  14. 'value' => format_date(strtotime('now'), 'custom', 'Y-m-d H:i:s', 'UTC'),
  15. 'timezone' => 'UTC',
  16. 'timezone_db' => 'UTC',
  17. );
  18.  
  19. // For datetime
  20. $node->field_datetest[$node->language][0]['value'] = "2011-05-25 10:35:58";
  21.  
  22. // For date
  23. $node->field_datetest[$node->language][0]['value'] = "2011-05-25T10:35:58";
  24.  
  25. // For datestamp
  26. $node->field_datetest[$node->language][0]['value'] = strtotime("2011-05-25 10:35:58");
  27.  
  28. $node->field_date[LANGUAGE_NONE][0] = array(
  29. 'value' => date('Y-m-d H:i:s', strtotime('now')),
  30. 'timezone' => 'UTC',
  31. 'timezone_db' => 'UTC',
  32. );
  33.  
  34. jQuery(document).ready(function() {
  35.  
  36. var fullDate = new Date()
  37. var HR_fullDate = fullDate.toDateString().toString().substring(4,15);
  38. jQuery('strong.date').contents().replaceWith(HR_fullDate);
  39.  
  40. });
  41.  
  42. $mydate = date('Y-m-d', strtotime('31 May 2011'));
  43.  
  44. $node->field_datetest[$node->language][0][value] = "2011-05-25T10:35";
  45.  
  46. $now = date_now('UTC');
  47. $now = date_format($now, "Y-m-d H:i:s");
  48.  
  49. // The date format in this sample is dd/mm/yyyy
  50. $form_state['values']['field_my_date_field']['und'][0]['value']['date'] = '14/05/2014';
  51.  
  52. function MY_MODULE_node_presave($node)
  53. {
  54. $node->field_date['und'][0]['value'] = '2014-09-23 00:00:00';
  55. }
  56.  
  57. function MY_MODULE_node_submit($node, $form, &$form_state) {
  58. if($node->type == 'my_node_type') {
  59. $test_date = $form['test_date ']['#value'];
  60. //Ensure that $test_date format is '2014-09-23 00:00:00'
  61. $node->field_date['und'][0]['value'] = $test_date ;
  62. }
  63. }
  64.  
  65. $entity->field_upload_time["und"][0]["value"] = time();
Add Comment
Please, Sign In to add comment