0
 [field_download_time] => Array
            (
                [und] => Array
                    (
                        [0] => Array
                            (
                                [value] => 2012-11-27 09:38:00
                                [timezone] => America/Phoenix
                                [timezone_db] => America/Phoenix
                                [date_type] => datetime
                            )

                    )

            )

What I see for a field_download_time is given above.. I am adding nodes programmatically so the code for following field is as given below

 $download_node->field_download_time[]['value'] = date('m-d-Y H:i', REQUEST_TIME);//--?     

I don't get an error on running the above code but the value of current date is not displayed

But When I run the following code given below I get an error THE ERROR :
Actually the code is such that when u go to the link it downloads a file .Basically the error is that file is not downloaded.

  $download_node->field_download_time['und'][]['value'] = date('m-d-Y H:i', REQUEST_TIME);//--?
7
  • Be sure to call node_save() after you've changed the value of the field. Until then it won't appear.
    – AjitS
    Aug 23, 2013 at 5:49
  • yes I have added node_save() but the value is not being displayed..
    – harshal
    Aug 23, 2013 at 6:02
  • try this $download_node->field_download_time['und'][0]['value'] = date('m-d-Y H:i', REQUEST_TIME);. After that add node_save($download_node);.
    – AjitS
    Aug 23, 2013 at 6:06
  • Yes I have done the same thing but it gives error when checked the node i got an empty array for field_download_time .also field_download_time is multiple value field so field_download_time['und'][]['value']
    – harshal
    Aug 23, 2013 at 6:09
  • please edit the question and add the error you're getting. Are you sure you've placed the key [0] between ['und'] and ['value']?
    – AjitS
    Aug 23, 2013 at 6:11

2 Answers 2

3
[0] => Array
                            (
                                [value] => 2012-11-27 09:38:00
                                [timezone] => America/Phoenix
                                [timezone_db] => America/Phoenix
                                [date_type] => datetime
                            )

As seen above, the error was occuring due to improper date format So when I changed the date format to date(Y-m-d\TH:i:s, REQUEST_TIME); the $download_node->field_download_time['und'][]['value'] did not gave any error .

1

Try this :

$mynode->field_download_time[LANGUAGE_NONE][0]['value'] = "2012-11-27";
$mynode->field_download_time[LANGUAGE_NONE][0]['timezone'] = "America/Phoenix";
$mynode->field_download_time[LANGUAGE_NONE][0]['timezone_db'] = "America/Phoenix";
$mynode->field_download_time[LANGUAGE_NONE][0]['date_type'] = "datetime";
1
  • yes this will also work.
    – harshal
    Aug 23, 2013 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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