I'm using drupal_execute to create an import process for a batch of nodes that contain dates. When I execute the script, I keep getting a "the dates are invalid" message. If I take the dates out of the import script, the node is created just fine, so I'm pretty sure this is related to the date module and how I'm formatting things, but I can't (after multiple days) figure out what I'm doing wrong.
I'm using date 2.4 on a drupal 6.14 install with CCK3 (in order to take advantage of the multigroup module). The date is inside a multigroup, but I get the same error message even when I take the date field out of the group and try importing it that way.
The date field itself is a "date" type (not datetime or datestamp). I'm using a select list widget, but originally I had it as a dropdown calendar (same import results for both widgets). Years backward and forward is set to -10:+10 and granularity is hour/minute/second (though I would prefer just y/m/d).
I was able to look at the $form_state array from a normal node form submission, and the field looks like this:
[field_action_date] => Array
(
[0] => Array
(
[value] => 2006-06-17T00:00:00
[_weight] => 0
[_remove] => 0
[value2] => 2006-06-17T00:00:00
[timezone] => America/Chicago
[offset] => -18000
[offset2] => -18000
)
)
I tried to mimic that format in my code, which looks like this:
$form_state['values']['field_action_date']['0']['value'] = '2006-06-17T00:00:00';
$form_state['values']['field_action_date']['0']['value2'] = '2006-06-17T00:00:00';
$form_state['values']['field_action_date']['0']['_weight'] = 0;
$form_state['values']['field_action_date']['0']['_remove'] = 0;
$form_state['values']['field_action_date']['0']['timezone'] = 'America/Chicago';
$form_state['values']['field_action_date']['0']['offset'] = -18000;
$form_state['values']['field_action_date']['0']['offset2'] = -18000;
Note that above I've hard-coded the values in for testing purposes. I get the same message for hard-coded date values as well as the real date values I'm trying to import, which are formatted the same way. I've also tried alternately assigning just the 'value', both 'value' and 'value2', and finally all the information you see above. Same result every time.
So, I'm pretty sure I'm doing something wrong, I just don't know what it is. I've marked this request critical because a fairly large rollout depends on me getting this to work as soon as possible (I hope that's not seen as rude; I'm just panicked). At this point, I'm willing to try anything, so any ideas would be welcome. If I've missed providing any relevant info, just let me know and I'll post it as quickly as possible.
Thanks!
Comments
Comment #1
tobi20 commentedI have the same problem. Could you find a solution for this?
Comment #2
himerus commentedI'm playing with the same issue right now. Everything else is working great, but it's something of how the date is actually created/structured for it's own validation. I think the above format is not appropriate until "after" the form has been processed.
When that is received in the $form_state array, it is already processed, and being sent back to the form, but the value of the field is the "normal" value as we would expect to see it.
I'll post back if I get the solution.
Comment #3
aleksey.tk commentedSame issue for me. Subscribing.
Comment #4
chalee commentedhave the same problem. subscribing
Comment #5
superlou commentedSame problem. Subscribing.
Comment #6
chalee commentedI ended up not using drupal_execute and using node.save instead and everything worked fine.
Comment #7
aleksey.tk commentedyes, i'm using node_save and it is working, but i recommend you to check your site date format (admin/settings/date-time/formats) - it can be different then your input.
Comment #8
dmotilla commentedHi, I'm testing this with node.save webservice, that use drupal_execute, and if the field looks like this, for me works correctly:
Date field format must to be like in node edit form. If you subscribe this, you can close this.
(Excuse my english :)
Comment #9
rnagy commentedThe following JSON worked for me with node.save via the JSON Server web service...
The Input Format for the date field was set to: "30 Oct 2010 - 8:19pm". Yours is likely to be different so you will need to change the above date/time values accordingly.
Comment #10
karens commentedTrying to clean up the issue queue so I can get a new release out. Support requests are not critical. Critical is for bugs.
Comment #11
haha789 commentedI'm having a similar issue using node_import with Date CCK Field. Seems like node_import first converts the date to the ISO format like this:
[field_test] => Array
(
[0] => Array
(
[value] => 2008-02-28T00:00:00
)
)
So no matter which format I try to import, the dates are allways converted in the right way.
But when importing I get a "The dates are invalid." error.
Any suggestions?
Comment #12
Anonymous (not verified) commentedThis seems to be related to: #799744: Validation error with drupal_execute()
Comment #13
dariogcode commentedFor D7 use this
Note that 'und' is for D7, I think D6 may be similar
I hope this help you don't spend hours like me debugging.
Comment #14
hypertext200To use above you should create the date field with date pop-up widget enabled.
Comment #15
damienmckennaWe're sorry but the D6 release of Date module is no longer being supported. You are encouraged to update to Drupal 7 or 8, or direct questions to Drupal Answers.