Saltar navegación

[Asignado] Help showing conditional date logic if event is TODAY() – Time creates conflicts

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zona horaria del colaborador: Asia/Kolkata (GMT+05:30)

Este tema contiene 4 respuestas, tiene 1 mensaje.

Última actualización por benS-19 11 hours, 43 minutes ago.

Asistido por: Minesh.

Autor
Mensajes
#2865621

I currently have a Date + Time field, which works as intended, but the issue comes from trying to show a message if the date is TODAY. The issue I’m having is it's taking the TIME into consideration when comparing the value, rather than the day as a whole.

The message/conditional below only shows IF it is the day AND on or past the time value, which isn't good for me as need the message up all day from midnight. I can't set the time to 00:00 as it needs to display the correct time e.g. 19:00.

[wpv-conditional if="( $(wpcf-draw-date) eq 'TODAY()' )"]
Draw is today!
[/wpv-conditional]

^ Is there a way to ask it to ignore the time when comparing the date, as this only shows the message if it's on or past the time as well as the day.

#2865624

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The thing is that as you have date and time field and it stores the date and time value as Unix timestamp.

In your case, you will have to write custom shortcode that will return the draw date without the time.

For example:
- Please try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/

function ts_draw_date_only_shortcode( $atts ) {
	global $post;

	$timestamp = (int) get_post_meta($post->ID,'wpcf-draw-date',true);

	if ( ! $timestamp ) {
		return '';
	}

	$dt = new DateTime( '@' . $timestamp );
	$dt->setTimezone( wp_timezone() );
	$dt->setTime( 0, 0, 0 );

	return $dt->getTimestamp();
}
add_shortcode( 'draw_date_only', 'ts_draw_date_only_shortcode' );

Once you create the code snippet within the "Custom Code" section, make sure to activate it and then also register the shortcode name draw_date_only at:
=> Toolset => Settings => Front-end Content tab => Functions inside conditional evaluations section.

Then you can compare it as:

[wpv-conditional if="( '[draw_date_only]' eq 'TODAY()' )"]
Draw is today!
[/wpv-conditional]
#2865644
Screenshot 2026-06-19 at 12-52-31.png
Screenshot 2026-06-19 at 12-52-40.png
Screenshot 2026-06-19 at 12-52-51.png

Hi,

Thank you kindly for your assistance, I've gone ahead and added the code in the relevant places (see screenshots) - but it's not being shown on the front-end.

I've also set the "Time" to a few hours ago (just to test), but it still doesn't show.

The wpcf- field is correct the Toolset shortname is draw_date, so not sure what is happening. - Any ideas, please?

Thank you.

#2865668

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I need to understand you just want to compare the draw_date is equal to today's date - that is it. Is that correct?

For example 2026-06-15 (draw_date ) equal to 2026-06-15 (for instance today's date)

Please let me know if you have any other comparision.

#2865778
Screenshot 2026-06-20 at 17-04-30  WordPress.png

Hi,

Yes, that's correct we show labels on various products depending on the date/time entered...the 3 x scenarios would be:

1. Show the Date + Time of a particular Date (normal) e.g ."June 20th 2026 at 15:00pm"...
2. IF the Date (day) is the same day as the selected date/day via the picker, then show "This message instead" e.g. "Today is the day"...
3. IF the Date has passed, then show "a third message" instead e.g. "Closed".

These conditionals/results are what I’m ultimately trying to achieve, and hope you'll be able to help.

Please see the attached. - To reiterate, what you've said is true, and I imagine if I just had a date field, then it would be more straightforward, but because in includes the "time" aspects as well, then the 2. message won't be true until that time has been reached.

Essentially we want to show the 2. message, as soon as it's the same day (full 24 hours), not match the time as well in order to activate the conditional.