Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I would like to set a specific date (not one relative to Now) as the default on a Date CCK Field, is there a way to do this? I've tried setting the default to relative and putting the date in as the default in numerous formats but none have worked.
Comment | File | Size | Author |
---|---|---|---|
#1 | date_popup.module.patch | 1.32 KB | Timo.Kissing |
Comments
Comment #1
Timo.Kissing CreditAttribution: Timo.Kissing commentedI spend about an hour today trying to set a date_popup element to a specific date. After playing around with different formats and values for #default_value, #value and #date_format, I finally looked at the code. I think there is actually a bug with the #default_value, it is never read in date_popup.module - maybe something similar is happening for you.
I finally got date_popup to work (and even accept a timestamp as input for #default_value) after patching the date_popup.module (see attachment). Maybe that will help or at least give you an idea where to look.
The corresponding code in my module that creates the date_popup element is:
$form['options']['mydate'] = array(
'#type' => 'date_popup',
'#default_value' => $node->mydate, // <- unix timestamp
'#title' => t('mydate'),
'#date_type' => DATE_UNIX,
'#date_timezone' => date_default_timezone_name(),
'#date_format' => 'd.m.Y H:i',
'#date_increment' => 15,
'#date_year_range' => '-1:+1',
);
*EDIT*
Sorry, the first "solution" was not really working. It solved one problem, but introduced another.
With the new patch / form element I can now save/display/edit as expected.
Comment #2
KarenS CreditAttribution: KarenS commentedThis would be a feature request. I'm focusing on fixing bugs now, not adding new features until the bugs are addressed.
Comment #3
arlinsandbulte CreditAttribution: arlinsandbulte commentedduplicate of #319195: Set default value to a custom strtotime string (for relative or exact dates)