[SOLVED] Date.add / DateHelper.php doesn't work for me

Hi,

I am unable to use the Date.add function.

test = ${Date.add(Date.create('today'), '2 days')}

Doesn’t work.
I have to edit the file DateHelper.php (Neos.Eel)

/**
     * Add an interval to a date and return a new DateTime object
     *
     * @param \DateTime $date
     * @param string|\DateInterval $interval
     * @return \DateTime
     */
    public function add($date, $interval)
    {
        
I added this line -->
        $interval = date_interval_create_from_date_string($interval);
        ------
        if (!$interval instanceof \DateInterval) {
            $interval = new \DateInterval($interval);
        }
        $result = clone $date;
        return $result->add($interval);
    }

Does the date.add function work for anyone without date_interval_create_from_date_string() ?

Thanks in advance
Bernd

You have to follow the syntax outlined here:

https://www.php.net/manual/en/dateinterval.construct.php

in your case: P2D

I find the idea to support the string syntax you used nice as well, but then that would be breaking. We might add it as separate method.

1 Like

Hi Christian,

Thank you very much for your fast and professional answer. I probably wouldn’t have found the solution even though I had been reading the PHP manual all day today. It finally worked, I’m very happy about that.

1 Like

btw Date.create('+2 days') should work, too

2 Likes