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?

2 Answers 2

10

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
  • 1
    i tried and the email message renders [node:field_calendar_date:short] or any of the tokens used
    – lakers2012
    Commented Dec 14, 2012 at 3:30
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]")
2
  • Well thats just annoying - duplicating all the tokens to provide alternate functionality. Thanks for the tip of (point 2)
    – Nick
    Commented Jun 2, 2014 at 11:26
  • Point 2 did it for me too. I never would have thought to try dashes! Commented Feb 10, 2016 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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