[Feature] to_datetime(date, format) filter to allow datetime calculations
Is your feature request related to a problem? Please describe. We are trying to calculate the difference in days between two dates.
Describe the solution you'd like An easy solution would be to add a filter that takes a date string and its format and returns a datetime object. This could enable a lot of different calculations depending on the users needs.
Describe alternatives you've considered I have considered using an extra field, but this feels like overkill for such a small issue. I could not find any default jinja2 or Ghostwriter filters that handle date/datetime parsing.
Additional context Example:
{% set project_start_date = project.start_date | to_datetime("%d %b %Y") %}
{% set project_end_date = project.end_date | to_datetime("%d %b %Y") %}
{% set project_duration_in_days = (project_end_date - project_start_date).days %}
The project took {{ project_duration_in_days }} days.
Implementation: https://github.com/GhostManager/Ghostwriter/compare/master...DeveloperMarius:Ghostwriter:feature/filter_to_datetime
We can look into this. If you already have an implementation on your branch, you're also welcome to submit it as a PR.
We've got a similar implementation but a Jinja filter that calculates working days which might be a bit more complicated than this ask
Hey,
i actually needed the same in the background but thought that this request may be too specific. I also have an implementation for this. @chrismaddalena what do you think?
Both options would be welcome additions 😄
We currently have a custom filter for adding business days to a date and formatting a date, but we do not have options for calculating date differences.
I created a PR containing both filters. Feel free to give feedback or suggest changes.
Thank you! Now that v6.1.0 is out, we will take a look at it.