hi there,

I want to set the default value of a date on a saturday + 4 weeks at 14:00.

When I try this in php code:
print date ('l d/m H:i', strtotime('next saturday +4 weeks 14:00'));
returns the date and time I expect
Saturday 31/10 14:00

When I set the same string as default for a date, it returns the wright date but not the wright time.

Can anyone help me?

thanks,
geert

Comments

gertieiv’s picture

Component: Date Popup » Date CCK Field
mrthumpz’s picture

I ran into the same wall when attempting to set the date field default to a semi-absolute. In my case I needed the last day of February in the current month. In strtotime, using "march 0" works for my case, always returning the last day of February for the current year. This would not work in the relative field, so I left the setting blank, and used hook_form_alter to edit the default for my field manually.

Here is what my code looked like: (replace module with the name of your module, and make sure to use your form id and field name

/**
* Implementation of hook_form_alter().
*/
function module_form_alter(&$form, $form_state, $form_id){	
	if($form_id == 'violation_review_node_form'){
		$exp = date("Y-m-d h:m:s",strtotime("march 0"));
		$form['field_expiration_date'][0]['#default_value']['value'] = $exp;
	}
}
HJKL’s picture

Thanks for the tip mrthumpz. It took me a while to realise it was giving me the wrong time because you have "h:m:s" (hour, MONTH, second) in your snippet. "h:i:s" works as I wanted.

karens’s picture

Status: Active » Postponed (maintainer needs more info)

Is there a bug or not? I can't tell what this issue is trying to get me to do.

arlinsandbulte’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)