Skip Navigation

[Resolved] Conditional Output compare dates

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I compare 2 Dates stored in Types Date Field?

Solution:
You can use HTML Conditional
For Conditional HTML comparison you shoudl use the output "Raw".

This will produce the Time Stamp number as stored in the DataBase and so you can compare an exact number.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 7 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Mr. DJ 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#408267

Hello there,

I have successfully used Conditional Output so many times, but this one is haunting me 😉

I have two date fields:
DATE-1
DATE-2

If DATE-1 and DATE-2 are equal
I want to display: Only on DATE-1

If DATE-2 is different (or larger etc) than DATE-1
I want to display: Available from DATE-1 to DATE-2

(I have to use two Date-fields for filtering etc. Leaving the DATE-2 field empty is not an option).

Can you help us out?

#408633

Well, Types Date Fields will return a Time Stamp.
That's a long number, not a humanly readable Date.

Only passing a Format, will render them as a date.
For Conditional HTML comparison I would use the output Raw.

This will produce the Time Stamp number as stored in the DataBase and so you can compare an exact number.

As a suggestion, also output the 2 Dates as time Stamps next to each other to see what they output.
This way you can see what the Conditional actually should produce.

Have you also consulted this DOC?
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

If all this does not work, please share with me the conditional Code you use.

#409195

Thanks Beda!

The fact that dates are stored as a number helped out.
I've build a Conditional Output that compares the two number (dates). If these are the same I output a different message.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.