Hi all, 

I'm trying to set up a path pattern for a content type that uses the value from a date field.  The date field is configured to collect only the year, but if I use the field's token in a path, it inserts the entire date format rather than just the year: 2012-01-01t000000 rather than 2012.

 

Anyone have any thoughts on how to address this? 

 

thanks!

Accepted answer

In the meanwhile you can create a new display mode called Token on a content type (or other entity) and adjust the date format there. Seems to work for people https://github.com/backdrop/backdrop-issues/issues/1425#issuecomment-451...

Most helpful answers

Custom tokens exist for node creation dates, for instance [node:created:custom:Y], but not for date fields, see a description of the issue here: https://github.com/backdrop/backdrop-issues/issues/2652.

Discussion and work to fix the issue happens mainly in https://github.com/backdrop/backdrop-issues/issues/1425, which still needs some work. There is a working pull request (PR), but it looks like the fix will take another approach (without PR so far).

Comments

Date fields always store the full date in the database, even if you just show part of it. To get just the year as a token in your paths, you can add ':custom:Y' to the end of the base token (e.g. [node:field_date:custom:Y]). Click the 'more' link next to the custom date token for a link to PHP's documentation on how to get the different parts of the date.

Olafski's picture

Custom tokens exist for node creation dates, for instance [node:created:custom:Y], but not for date fields, see a description of the issue here: https://github.com/backdrop/backdrop-issues/issues/2652.

Discussion and work to fix the issue happens mainly in https://github.com/backdrop/backdrop-issues/issues/1425, which still needs some work. There is a working pull request (PR), but it looks like the fix will take another approach (without PR so far).

Thanks all, that was just what I needed!