studioespresso / craft-date-range

Date range field for Craft CMS
MIT License
12 stars 6 forks source link

Get start and end date as a date object #27

Closed helleholmsen closed 3 years ago

helleholmsen commented 3 years ago

Hi! I need the start and end-date as seperate date objects. Is this possible?

I'm using the craft3-calendarlinks plugin to generate isc links and there you need to have a from and to date fields like this:

{% set downloadLink = craft.calendarLinks.create({
    from: now|date_modify('+1 hour'),
    to: now|date_modify('+3 hours'),
}) %}
helleholmsen commented 3 years ago

Never mind! I just noticed I can access this with fieldHandle.start and fieldHandle.end :)

janhenckens commented 3 years ago

Cheers @helleholmsen, happy to see you found it! Feel free to make a new issue if you run into anything else :)

helleholmsen commented 3 years ago

@janhenckens thanks! 🎉

gracehcoote commented 11 months ago

Sorry to reopen this issue, I am having trouble accessing the start and end values of my date range field. I am trying to output dates as follows: 01 Apr - 09 June 2024 - in this scenario ideally the year would only output once if it is the same year. I am hoping that by accessing the start and end values I can compare the year but I'm not having any luck and just keep getting errors, so I am definitely using it wrong!

I was initially using {% set dates = event.dates.formatted("j M Y") %} to format the dates appropriately, but the main issue is only outputting the year once if they match.

Any help on this would be greatly appreciated.

janhenckens commented 11 months ago

@gracehcoote you could use event.dates.start and event.dates.end, that way you can write your own logic to set the correct formats when you need them.