I am using a date field to specify the start and end times of a content type for gigs. I would like to default the start time to something like '21:45 today'

The only options for the default value are 'blank', 'now' and 'relative'.

My problem is that 'relative' means an offset relative to 'now', which is the current time. An obvious fourth option would be to let you set the default value to an arbitrary strtotime string like '21:45 today'

Can someone point me in the right direction to hack this in.

...Or failing that just some way to choose 'relative' meaning relative to 'today' (ie midnight - beginning of today) instead of 'now' would suffice

Comments

blueskiwi’s picture

I should just correct the above... on my install strtotime('21:45 today') just returns the same as 'today' even though the gnu date format docs mention a phrase just like that.

I have to use strtotime('today 21:45') to get the value I want.

And I still can't use it as a default for the date field...

KarenS’s picture

Assigned: blueskiwi » Unassigned
Category: support » feature

There is probably no easy way to do that now (or maybe no way to do it at all) but it is a logical feature request. I'm not sure about using strtotime() for the default, since it returns results that can be different depending on the system it is installed on, but having a way to set it to a specific time of the current day could be useful.

There are other requests for more ways to set the default value. The biggest problem is finding a way to make it as flexible as possible without having a totally confusing array of options to select from.

And you're not 'assigned' to do this, unless you're planning to provide a patch?

blueskiwi’s picture

thanks for getting back. For my site the data entry is being done on the admin side rather than user side so I will probably just live with having to type 21:45 when creating a record, since I don't have time to make a good patch at the mo.

my suggestion would be... you currently have three options: 'blank', 'now' and 'relative (to now)'

you could combine the last two (i.e. 'now' is just 'relative to now' with no modifier), and add a choice of relative - to what? the two useful ones I can think of are 'now' and '00:00 today'

arlinsandbulte’s picture

Version: 6.x-2.0-rc3 » 6.x-2.x-dev

+1 This sounds like a great request to me.
I marked #246292: Default option "absolute" in addition to 'blank', 'now', or 'relative' as a duplicate of this issue. That was really just a more specialized case of this feature request.

arlinsandbulte’s picture

Title: Can't set default value to a custom strtotime string » Set default value to a custom strtotime string (for relative or exact dates)

I like the idea of using strtotime() for specifying a default date. Karen has some reservations above, but I think this is done in other areas of Date, or perhaps we could use another function or standard format to calm those fears.

This issue could be solved simply & elegantly if we changed the default choices to only two:
'blank' or 'enter a date string'

That 'date string' could be any valid strtotime string like:
now
now + 1 week
Last Thursday
July 10, 2010

[edit]
Actually, now that I think about it some more, maybe we could eliminate the select list all together & just use a single text field. For setting the default to 'blank', just leave the text field blank. Otherwise, if a default is desired, just put a valid entry in the text field.

Melissamcewen’s picture

Subscribe.

strellman’s picture

Subscribe. Need exact date.

Murz’s picture

Subscribe

adamdicarlo’s picture

Subscribe.

Because date_modify() is used, we can't put the default value as, e.g. "9:00am". date_modify() just doesn't understand that for some reason. I guess it's because it's not relative--but it really is relative to today's date if you ask me. I can't find any documentation on php.net particularly specific to how modify()'s language differs from strtotime()'s. Ugh.

For now to set, e.g., "tomorrow 14:30" I'll have to use a form alter. :/

TommyK’s picture

subscribe

drupalnesia’s picture

This is very simple to solve by using form_alter hook. Or you still need a patch?
I think better we add "ABSOLUTE" option as described well here: http://drupal.org/node/246292

Agileware’s picture

Subscribing

WorldFallz’s picture

I'm having trouble getting this done with a form_alter-- if anyone has sample code that would be awesome. thanks.

Agileware’s picture

I am using:

<?php
  if ($form_id == 'nodetype_node_form') {
    // Set the default date released value as the date module can't handle
    // much in the way of default values. See drupal.org/node/319195
    // Default to the start of the year.
    $current_year = date('Y');
    $form['field_mydatefield'][0]['#default_value']['value'] = $current_year . '-01-01 00:00:00';
  }
?>

This sets to the start of the current year.
You could also set to any specific date.
There is also a chance that the format of the default value may differ depending on the type of date field you are using but I don't know about that.

WorldFallz’s picture

Thanks for posting that! After wasting lots of time trying different variations at http://drupal.org/node/726282, I finally did try that simple tried and true method and I can confirm it does indeed work.

DamienMcKenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.