Ghostwriter icon indicating copy to clipboard operation
Ghostwriter copied to clipboard

[Feature] to_datetime(date, format) filter to allow datetime calculations

Open DeveloperMarius opened this issue 2 months ago • 6 comments

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

DeveloperMarius avatar Nov 21 '25 14:11 DeveloperMarius

We can look into this. If you already have an implementation on your branch, you're also welcome to submit it as a PR.

chrismaddalena avatar Nov 25 '25 00:11 chrismaddalena

We've got a similar implementation but a Jinja filter that calculates working days which might be a bit more complicated than this ask

domwhewell-sage avatar Nov 30 '25 10:11 domwhewell-sage

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?

DeveloperMarius avatar Nov 30 '25 12:11 DeveloperMarius

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.

chrismaddalena avatar Dec 01 '25 20:12 chrismaddalena

I created a PR containing both filters. Feel free to give feedback or suggest changes.

DeveloperMarius avatar Dec 02 '25 07:12 DeveloperMarius

Thank you! Now that v6.1.0 is out, we will take a look at it.

chrismaddalena avatar Dec 05 '25 21:12 chrismaddalena