2

I am having difficultly learning how to do a case statement in magento 2. Most what i see is magento one and few of the examples the function they say to use does not exist.

All i am trying to do is the follow

CASE WHEN DATEDIFF(NOW(),public_date)  <= 30 THEN 1 ELSE 0 END AS new_video

I tried to use something like the following but nginx fails out.

->addExpressionAttributeToSelect('new_video', 'CASE WHEN DATEDIFF(NOW(),public_date)  <= 30 THEN 1 ELSE 0 END','')

I get that i can use addExpressionFieldToSelect for functions but for case i am unsure since magento whats to tack on the alias main table to everything that i use.

addExpressionAttributeToSelect, nginx kicks back saying that function cant be found. Whats the proper way to do this case statement

Thank you, Hopefully the magento community doesnt fail me.

1 Answer 1

0

Did some digging and some guessing and this appears to be the correct solution to my case statement

->addFieldToSelect(new \Zend_Db_Expr("CASE WHEN DATEDIFF(NOW(),public_date)  <= 30 THEN 1 ELSE 0 END AS new_video"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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