3

Is it possible to store partial dates? EG i want to create a document that covers a date range, sometimes that range could be Jan/2013 to JUN/2014 other times we may need it more specific EG 20/JAN/2013 to FEB 2014 and sometimes even less specific like 2013-2015.

Would i need to create a new custom field type?

2
  • Would it not be acceptable to say, in the case of a "general" date range, you set the dates to i.e. 1st day of start month - last day of start month? Since programatically if you're filtering you'd have to do that anyway. Alternatively you could have a "Tentative date" checkbox on your document entry that, when checked, means you don't output the day portion of the date. That's a bit easier than making a new field type.
    – JamesNZ
    Commented Nov 13, 2018 at 3:50
  • I was thinking this as an option. So i think i will use this method! Thanks for your input. Commented Nov 13, 2018 at 9:55

1 Answer 1

1

I'd set this up with regular date fields. You can then display the dates in whatever format you require on the front end using Twig's date formatting filter.

With the data stored as dates you can do a lot more with it compared to simply storing strings.

If you need to show a date range, such as "2013-2015" then it would probably be best to use 2 fields. A "date from" and a "date to" field. You could then use some logic to display one, or both, depending on whether there was something in the "date to" field.

1
  • Yeh but the problem is you have to provide a full date in those fields. You cant just put the year in or month/year Commented Nov 12, 2018 at 16:16

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.