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.

#1 date_popup.module.patch1.32 KBTimo.Kissing
Members fund testing for the Drupal project. Drupal Association Learn more


Timo.Kissing’s picture

1.32 KB

I 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',

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.

KarenS’s picture

Version: 6.x-2.0-rc4 » 6.x-2.x-dev
Category: support » feature

This would be a feature request. I'm focusing on fixing bugs now, not adding new features until the bugs are addressed.

arlinsandbulte’s picture