I've got a rule with php condition. I'm trying to compare 2 dates. the problem comes from the node date.

Here is a part of my script:

$date= date("Y-m-d");
$node_date= ("[node:field_event_date]");

$myDateTime = DateTime::createFromFormat("Y-m-d H:i:s", $node_date);
echo $myDateTime->format("d-m-Y");

I would like to convert my date and time to a different date format (d-m-Y was set on purpose to test the script, but eventually the format would be Y-m-d).

The date i'm pulling out has this format: yyyy-mm-dd H:i:s (i did an echo $node_date ) but i can't convert it using "createFromFormat". Even though when i enter a date with the same format that "$node_date", instead of the variable, it works...

So i don't really know any more what to do...i feel i got the solution, but cannot make it.

Thanks for your help


I don't know if my solution is actually going to help, but I had a similar issue not with the node date but with a date field in a content type.

For some reason I was not able to properly expose the date field for comparison, and there are some slightly relevant issues about this in Rules issue queue. So what I did was to expose the field using the Views Rules module.

Although this is just a work-around really, with a performance penalty, it turned out to me that with this way the exposed field could then be used directly in comparisons.

| improve this answer | |
  • Thanks for the advice, i'll check out and let you know ! – Ryan Dec 12 '14 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.