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?

  • 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 Nov 13 '18 at 3:50
  • I was thinking this as an option. So i think i will use this method! Thanks for your input. – Dean Sanderson Nov 13 '18 at 9:55
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.

  • 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 – Dean Sanderson Nov 12 '18 at 16:16

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.