Would it be possible to have a token for date fields with which we could use a custom date format, like what is provided for [node:created:custom:?].

I have an date field on a custom event content type, and would like to use a token like [node:field_event_date:custom:?]

Comments

newbstah’s picture

+1

pmusaraj’s picture

+1

bneil’s picture

Status: Active » Closed (duplicate)
bneil’s picture

Project: Token » Date
Version: 7.x-1.0-beta7 » 7.x-2.x-dev
mxt’s picture

At today, using all the latest DEV version of involved modules, I have now a WORKING token to obtain paths with custom format date like:

events/2012/my-event-title

The token I use is:

events/[node:field-mydatefield:value:custom:Y]/[node:title]

hope this help

iamcarrico’s picture

I attempted to do the same--- but was not successful. Which releases / modules are involved (if there is more than just date and token).

wimvds’s picture

@ChinggizKhan In case you haven't found out already : you have to enable both Entity API and Entity Tokens to make it work (btw it also works using the stable version of Date).

iamcarrico’s picture

@wimvds Thank you! It was on my back burner. I assume I need the dev releases of Entity API and Entity Tokens, while just the stable version of Date.

EDIT: All you need is the latest stable date, entity api and entity tokens enabled. Works great.

mrpauldriver’s picture

Entity token does not appear to like spaces when used in the custom date, printing the token as below rather than the replacement.

[node:field-my-date:custom:jS F, Y]

I can work around this by using hyphens, like this... [node:field-my-date:custom:j-S-F-Y]

I don't know any php and wonder if there is a proper method for printing spaces.

elvis2’s picture

I know this is ugly but one way around your problem is this:

[node:field-my-date:custom:jS] [node:field-my-date:custom:F], [node:field-my-date:custom:Y]

espurnes’s picture

events/[node:field-mydatefield:value:custom:Y]/[node:title] is not working for me in a field with start and end date.

It works with field without an end date. Maybe this helps someone.

I tried solution in http://drupal.org/node/1621084 but it doesn't work for me with date fields with end date.

kaizerking’s picture

@ MXT #5 your tip has helped me a lot thanks to you

charlie charles’s picture

I'm using the token for date

%node:field-date-available

Which comes out as

"Wed, 04/24/2013 - 00:00"

Do you know how to format it as this please?

"04/24/2013"

Many Thanks for your help

kaizerking’s picture

if you do not want to use H:i:s, create a new date format at admin/config/ date and create 'd/m/Y' (without quotes)
use that format where ever u need

charlie charles’s picture

Thank you :)

charlie charles’s picture

Sorry, I've added the new date format
admin/config/ date

Add it as a new date type "my date type"

How do I add the new date format to the token please?

%node:field-date-available

Many Thanks again for your help

traveller’s picture

Thanks for the tip, #5, the following pattern for 'event/year/month/day/node-title' worked for me:

event/[node:field-event-date:value:custom:Y]/[node:field-event-date:value:custom:m]/[node:field-event-date:value:custom:d]/[node:title]

abarpetia’s picture

Issue summary: View changes

@ espurnes #11: did you found out a solution??
Thanks in Advance.

rwilson0429’s picture

Date fields which have end dates are exposed to the entity token system as structs with three properties: value, value2, and duration. When a date field is configured to have multiple values, then the token type is set to list

. See https://www.drupal.org/node/1621084. These apparently were not supported until the patch at https://www.drupal.org/node/1621084 was committed.

Using the dev versions of Path Auto, Entity API and Entity Tokens modules, I was able to setup a URL Alias path using tokens for content having a custom repeating date field (field_event_date) configured to have a start and an end date and with unlimited cardinality.

event/[node:field-event-date:0:value:custom:Y]/[node:field-event-date:0:value:custom:m]/[node:title]

This created a url path of event/yyyy/mm/title (e.g "event/2015/11/My Content Title") based on the date value in the field_event_date field of the node.

Without adding the cardinality value, "0" in my case, to the format, the tokens didn't work.

pslcbs’s picture

Thank you @rwilson0429! I had the exact same issue and fixed it with your solution over:

Drupal 7.41
Date 7.x-2.9
Entity API and Entity tokens 7.x-1.6
Pathauto 7.x-1.3

philchen’s picture

In the case where you want to format as 1/2/2016 use the following for your token
[field-start-date:custom:m/d/Y]

davidneedham’s picture

I realize work isn't here anymore in favor of #1103032: Document how to use date tokens, however I tried a ton of options based on suggestions from this and several other issues and I wanted to share what I found. In our particular use case we're formatting a date field on a content type that is related to a particular registration. We want to use this in a rule to email out a particular date for the event.

Here's everything I tried:

date:0: [registration:entity:field_date:0]
date:0:custom:Y: [registration:entity:field_date:0:custom:Y]
date:0:long: [registration:entity:field_date:0:long]

date:0:value: [registration:entity:field_date:0:value]
date:0:value:custom:Y: [registration:entity:field_date:0:value:custom:Y]
date:0:value:long: [registration:entity:field_date:0:value:long]

dashed-date:0: [registration:entity:field-date:0]
dashed-date:0:custom:Y: [registration:entity:field-date:0:custom:Y]
dashed-date:0:long: [registration:entity:field-date:0:long]

dashed-date:0:value: [registration:entity:field-date:0:value]
dashed-date:0:value:custom:Y: [registration:entity:field-date:0:value:custom:Y]
dashed-date:0:value:long: [registration:entity:field-date:0:value:long]

date: [registration:entity:field_date]
date:custom:Y: [registration:entity:field_date:custom:Y]
date:long: [registration:entity:field_date:long]

date:value: [registration:entity:field_date:value]
date:value:custom:Y: [registration:entity:field_date:value:custom:Y]
date:value:long: [registration:entity:field_date:value:long]

dashed-date: [registration:entity:field-date]
dashed-date:custom:Y: [registration:entity:field-date:custom:Y]
dashed-date:long: [registration:entity:field-date:long]

dashed-date:value: [registration:entity:field-date:value]
dashed-date:value:custom:Y: [registration:entity:field-date:value:custom:Y]
dashed-date:value:long: [registration:entity:field-date:value:long]

Of these options, here are all of the ones that worked and their values:

date: 2016-04-25 00:00:00
dashed-date: Property field_date
dashed-date:value: Mon, 04/25/2016 - 00:00
dashed-date:value:custom:Y: 2016
dashed-date:value:long: Monday, April 25, 2016 - 00:00

Here's why I suspect these worked:

  1. The entity token module uses dashes instead of underscores.
  2. [registration:entity:field_date] is underscores, so from tokens, and returns the unformatted date because there is no other data.
  3. Dashes mean entity tokens, which is returning an object (??) - so it shows the name rather than data.
  4. Value is needed to return the data on the entity because we have an end date. value = start, value2 = end, duration = duration.
  5. I don't need "0" in there as some have suggested, because my date field only allows one value. If you have unlimited or some other number, you will probably need that.

I hope this is helpful to someone else coming across this, and I hope that you don't have to spend as much time I as did debugging this! :-)

dang42’s picture

Ran across this (specifically #22) trying to figure out how to use a custom date format (defined in admin/config/regional/date-time) in my rules-generated email. I've done it before, but it's been a while and for the life of me I couldn't remember how I'd done it in the past (unheard of, I know... :)

I suspect the way the example is formatted is pretty standard and that many (most?) folks understand it right away, but I was a bit confused by it. Just in case anyone else is looking for this info and isn't immediately clear on the example above, here's what I eventually figured out / remembered:

The goal - display the start time of a class (ex - "9:00am") in the subject line. There's just a single date on the node (start time only, no end time).

- The token for the full date (found under "Replacement Patterns") is [class:field-class-date] (what I'll call the "base token - don't know if there's a proper name for this...)
- The name of the custom date format is "Time only"

I got my desired output by adding the string ":time_only" to the end of the base token, like this --> [class:field-class-date:time_only]

aporie’s picture

Waouw thanks for your sharing davidneedham, saved me hours (even if I spent a lot of time on it).

gluebox’s picture

Reading through this thread, the fix for me was found over here: https://www.drupal.org/project/date/issues/1103032
#117

Requested Dates
From: [node:field-start-time:0:value:custom:m/d/Y]
To: [node:field-start-time:0:value2:custom:m/d/Y]

loudpixels’s picture

Hi there,

Is it possible to use time offset with a date token ... I'm trying to setup the node title to automatically generate the date of tomorrow [date] + 1 day. Any help would be greatly appreciated. Thanks!