Having some difficulties with my if/else statements recognizing my date and time greater or less than properly in my custom WordPress theme using ACF.
I think I may have it narrowed down to that is comparing strings instead of timestamps from this post but am baffled how to output that properly in twig? Here would be an example of what I currently have:
{% set dateandtime = fn('wp_date', "F j, Y g:i a") %}
{% set salestart = post.sale_start | date("F j, Y g:i a") %}
{% set saleend = post.sale_end | date("F j, Y g:i a") %}
and then:
{% if salestart >= dateandtime %}
<p>This sale will start {{salestart}}.</p>
{% elseif dateandtime >= salestart and dateandtime <= saleend %}
<p>This sale will end {{saleend}}.</p>
{% elseif dateandtime >= saleend %}
<p>Sorry this sale has ended as of {{saleend}}.</p>
{% endif %}
I think my issue is that its comparing strings instead of real datestamps but not quite sure what to do differently?
{{ dump(dateandtime) }} ouputs: ~src\Extension\DebugExtension.php:70:string 'July 31, 2021 2:43 pm'
{{ dump(salestart) }} ouputs: ~src\Extension\DebugExtension.php:70:string 'August 4, 2021 9:00 pm'
{{ dump(saleend) }} ouputs: ~src\Extension\DebugExtension.php:70:string 'August 6, 2021 5:00 pm'
I tried fiddling with |format_datetime()
from Twig Docs but didn't have much success? A clear explanation will be much appreciated as I am still a noob at this :)
~ Thank-you!