Hello,

At the moment, convert data can convert a date to a string, but the output can only be a Linux timestamp.
It would be useful to be able to provide a format, and even a timezone, to get a usable string (to put in a mail, display to a user...).
Patch will follow.

David

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David Stosik’s picture

Status: Active » Needs review
FileSize
13.85 KB

Here is the patch.
Feel free to test and give me a feedback.
David

David Stosik’s picture

Status: Needs review » Needs work

My code breaks other actions, such as "Add a variable", but I don't know why yet.
Any help is welcome!

David Stosik’s picture

Status: Needs work » Needs review
FileSize
14.08 KB

Here is a better patch, that does not seem to break anything.

David

fonant’s picture

Patch #3 works for me, and handy workaround for formatting dates as strings in rules. Thanks!

David Stosik’s picture

Here is a new version working on Rules-2.x branch, with a small fix concerning date custom format.

David Stosik’s picture

Actually, previous patch was just a reroll. This one here fixes the custom date format field.

Regards,
David

4kant’s picture

David, I tried your patch #6 - it is exactly what I needed and works fine.
I needed to set an ISO Date value for a text field (to hand the string over to Facebook to post an event on a Facebook page via module fb_autopost)

Great job

Thanks

rbrownell’s picture

Status: Needs review » Reviewed & tested by the community
fago’s picture

Title: Convert date to string using a date format (and a timezone) » Add actions to format dates and durations
Status: Reviewed & tested by the community » Needs work

Thank you for the patch.

However, I'm not so happy with the increased complexity it adds to the data type conversion action. Also, I don't think formatting a date is something that should be handled in a date conversion action - it's way more than just converting the data type, it's formatting. So this qualifies as a separate action.

Note, that we have intervals as separate data types also ("duration"), so I think we shouldn't bake formatting durations into the same action either but use another one. I don't know whether core has any built-in duration formats, I guess not - in which case we'd have to roll our own as the patch does.

fago’s picture

Issue tags: +Need tests

oh, and I forgot - we'll need test coverage for that.

jsibley’s picture

Issue summary: View changes
Issue tags: -

So, please, where does this leave us? I would like to format a date to show only the date without a time.

If this patch won't be committed what solution is there?

Thanks

jsibley’s picture

duplicate comment by mistake

TR’s picture

Status: Needs work » Closed (won't fix)

This can be done in D8 using Data Filters. See https://www.drupal.org/docs/8/modules/d8-rules-essentials/token-replacem...
I have already contributed more than my share to getting that implemented.

There doesn't seem to be any community support for doing this in D7 - it's been more than 7 years since anyone contributed anything to this issue, despite there being ~250,000 users of D7 Rules. So I don't see any need to keep this issue open any longer.