7

I'm using a rule to send out emails when a node is created. Under Action and Message body, I insert [node:field_calendar_date]. The token is replaced with (for example) "2012-12-14T08:00:00" in the email message, but I would like it to be replaced with "Friday, December 14, 8:00am" (same date, but a different format).

I tried to follow format_date(), but it doesn't work.

How can I get the format I want?

9

You can use [node:field_calendar_date:custom:l, Fd, gia], if [node:field_calendar_date] is a date token. In that case, [node:field_calendar_date:custom] returns the date in the custom format listed after the following colon. The format string is the one accepted by date().

If you want to use the format set as short/medium/long format set in the Drupal date settings, then you can use the following tokens:

  • [node:field_calendar_date:short]
  • [node:field_calendar_date:medium]
  • [node:field_calendar_date:long]
  • 1
    i tried and the email message renders [node:field_calendar_date:short] or any of the tokens used – lakers2012 Dec 14 '12 at 3:30
  • 1
    Did this work for anyone? For me it does not work with anything behind the date field in any way. Do you have to install something else or modify any token in any way? – reptilex Jan 15 '14 at 13:06
  • 1
    Same issue for me. As far as I can see, "node changed" replacement token explicitly proposes [node:changed:custom:?], which is not the case with date fields (at the best enabling "Entity tokens" from Entity API offers more options, like display start and end date when available, but still no custom display). – WhiteWinterWolf Feb 23 '14 at 16:22
8

OK, got it, it is not working even if I do not really understand the logic under the hood... Actually, the two blocking issues I had were the following:

  1. A date may be a range, therefore [node:field_date] cannot be considered as a date token. Install Entity API and enable the module "Entity tokens" to get access to the actual date value,
  2. Beware that for an obscure reason Entity token replace the underscore ([node:field_date...) of the original tokens name by a dash ([field-date...), you will then have access to a properly formatted date (in my case "[node:field-date:value:custom:Ym]", in the original question I guess therefore "[node:field-calendar-date:value:custom:l, F d, gia]")
  • Well thats just annoying - duplicating all the tokens to provide alternate functionality. Thanks for the tip of (point 2) – Nick Jun 2 '14 at 11:26
  • Point 2 did it for me too. I never would have thought to try dashes! – davidneedham Feb 10 '16 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.