Operations on date

Forminator Forms
3 March, 2023 02:22:16
Mohamed
Topics: 4
Messages: 16
Hello,
I use this code : [e2pdf-format-output explode="/" output="{0}"]<b>{date-1}</b>[/e2pdf-format-output] to show the day date (for example 01). But when I want to do operation on 2 dates, the result appears as string. For example, I have tried 16/03/2023 and 26/03/2023: [e2pdf-format-output explode="/" output="{0}"]{date-2}[/e2pdf-format-output] - [e2pdf-format-output explode="/" output="{0}"]{date-1}[/e2pdf-format-output]. I get 26-16 not 10. I know why this result (string - string). But I don't find the good method in the documentation.
Thanks
3 March, 2023 03:19:28
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

Unfortunately, E2Pdf currently doesn't have "math" operations built in. You need to use the custom filter.

Here is an example of a code snippet that must be added to your theme functions.php: https://codeshare.io/K8EM68

And inside E2Pdf Template, it must be used value as:

[e2pdf-format-output filter="days_difference"]{date-2}/{date-1}[/e2pdf-format-output]

We remain at your service.
We would really appreciate your feedback at WordPress.org!
5 March, 2023 06:29:44
Mohamed
Topics: 4
Messages: 16
Thanks for your answer.
I have an error when I write these dates: {date-1}= 26/03/2023 and {date-2}=16/04/2023. The result is (-10)
Mohamed
5 March, 2023 07:42:41
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

If you copied the shortcode from the previous message as:

[e2pdf-format-output filter="days_difference"]{date-2}/{date-1}[/e2pdf-format-output]

It's correct: 16 - 26 will be -10.

If you need {date-1} - {date-2} - swap the field slugs as:

[e2pdf-format-output filter="days_difference"]{date-1}/{date-2}[/e2pdf-format-output]
We would really appreciate your feedback at WordPress.org!
5 March, 2023 09:05:01
Mohamed
Topics: 4
Messages: 16
I'ld like to calculate the number of days between 2 dates.
5 March, 2023 11:19:41
E2Pdf
Support
Topics: 7
Messages: 3163
It's a completely different task, as the month has a different number of days.

You need to use the current function:

https://codeshare.io/eV6bmx

And shortcode as:

[e2pdf-format-output filter="days_difference"]{date-1}-{date-2}[/e2pdf-format-output]
We would really appreciate your feedback at WordPress.org!
6 March, 2023 02:40:37
Mohamed
Topics: 4
Messages: 16
Thanks.
The code give an error. I corrected it by replacinge "-" in this line ($dates = explode('-', $value);) by "*" et it works perfectly.
Can I ask you to do me a filter for the date before 2 days. For example, if I have the date 01/01/2024, I hop obtain automaticaly the date 2 days before:30/12/2023.
6 March, 2023 02:52:13
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

If you need it separately from your previous code, you must be able to use a shortcode wrapper as:

[e2pdf-format-date offset="-2 days" format="d/m/Y"][e2pdf-format-output search="/" replace="."]{date-1}[/e2pdf-format-output][/e2pdf-format-date]

P.S. Keep in mind please that it's very important you print the date example exactly as it prints in PDF with the default shortcode, as 30/12/2023 is not the same as 30.12.2023 or 30-12-2023. It can differ depending on field setup and WordPress date settings.
We would really appreciate your feedback at WordPress.org!
9 June, 2023 08:49:14
Mohamed
Topics: 4
Messages: 16
Hi,
How can I integrate a forminator field (ex:{number-2}) into a filter as like? :
[e2pdf-format-date offset="{number-2} days" format="d/m/Y"][e2pdf-format-output search="/" replace="."]{date-1}[/e2pdf-format-output][/e2pdf-format-date]
Thank you in advance
Mohamed
9 June, 2023 09:39:35
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

Unfortunately, currently, the only way is to use own created filter with PHP as:

https://codefile.io/f/MtMWoR5W3E

After the code will be added as a PHP Snippet or to your theme functions PHP, you must use the shortcode inside E2Pdf Template as:

[e2pdf-format-output filter="days_offset"]{number-2}|{date-1}[/e2pdf-format-output]
We would really appreciate your feedback at WordPress.org!
17 June, 2023 01:18:11
Mohamed
Topics: 4
Messages: 16
{date-1}=15/06/2023
{number-2}=15
This code gives me this result : 15|15/06/2023
Thanks in advance
17 June, 2023 03:49:20
E2Pdf
Support
Topics: 7
Messages: 3163
Hi,

Are you sure that it was added code to your functions.php as it seems missed: https://codefile.io/f/MtMWoR5W3E and you do not have mistakes in the shortcode:

[e2pdf-format-output filter="days_offset"]{number-2}|{date-1}[/e2pdf-format-output]
We would really appreciate your feedback at WordPress.org!
17 June, 2023 08:03:03
Mohamed
Topics: 4
Messages: 16
Thanks, it's my bad. I updated my them so the function is cleaned. Can I use just code snippets without integrate code in the function theme?
Also I try to apply this shortcode : [e2pdf-format-output filter="days_offset" explode="/" output="{0}"]{number-2}|{date-1}[/e2pdf-format-output] for having just the day of the date but in vain.
Thanks
17 June, 2023 08:16:47
E2Pdf
Support
Topics: 7
Messages: 3163
Yes, the PHP snippet also must be okay instead of functions.php.

To output just the day, you must be able to modify the "format" to "d" attribute in the code as:

$output = do_shortcode('[e2pdf-format-date offset="' . $offset . ' days" format="d"]' . $date . '[/e2pdf-format-date]');
We would really appreciate your feedback at WordPress.org!
17 June, 2023 10:17:39
Mohamed
Topics: 4
Messages: 16
But such that isn't practical because I'ld like to show separately day, month and year.
17 June, 2023 10:45:37
E2Pdf
Support
Topics: 7
Messages: 3163
Here is an updated code, replace please the old one:

https://codefile.io/f/wJ0uL6EgkO

After the code update, you must be able to use the "date_format" attribute:

[e2pdf-format-output filter="days_offset" date_format="d"]{number-2}|{date-1}[/e2pdf-format-output]

[e2pdf-format-output filter="days_offset" date_format="m"]{number-2}|{date-1}[/e2pdf-format-output]

[e2pdf-format-output filter="days_offset" date_format="Y"]{number-2}|{date-1}[/e2pdf-format-output]


We would really appreciate your feedback at WordPress.org!