Hi, I've got my custom content type created, and for the From date, I really want to set the default as a specific time (using today's date is fine, but I'd like the time to be, say, 6:30pm). It looks like strtotime should do this, but the help field on the default box says it needs to be relative to today's date/time, which in my case doesn't seem to apply (I've tried passing various values, such as "2010-01-01 6:30pm", and even just 6:30pm, and a few others). Is there a way to accomplish this?

Comments

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;
	}
}
donquixote’s picture

Title: How to set default date with specific time » Set default date with specific time (next friday 20:00)
Category: support » feature

This qualifies as a feature request. I'm missing it!

hook_form_alter() can do the trick, but it's not a very flexible solution. What if I create a new field that should behave the same? What if the field goes into a field group? Etc.

strellman’s picture

Version: 6.x-2.4 » 6.x-2.6

I am trying to figure out how to set the default to 2011-01-22
That seems like it should be easy, but it is all relative.
Maybe there is some way to pull that in from an event node reference.
I don't even see a place to put PHP if I knew how.

Found this http://drupal.org/node/319195

arlinsandbulte’s picture