5

NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Display a Message When Comparing Two Dates
Facile

---- Last modified : 23 November 2021

With this tutorial, we will show you how to create a condition that will display a message when comparing two dates or a hyperlink following the dates.

For example, you want to define a condition that today’s date is less than the date from a dynamic result.

We will need to generate our dates in a specific format (Date : 01-01-20 for our current example) with strtotime. To generate the current day’s date we will use get_the_date(format).

Here is the condition:

<?php 
$datetoday = strtotime(get_the_date('d-m-y')); 
$dateconference = '01-01-21'; 

if ( ( $datetoday > $dateconference) ) { ?>
<?php echo 'Disponible prochainement'; ?>	 
<?php } else { ?>
<a href="" class="bouton-print"><?php _e('Remplir', 'nomdevotretheme'); ?></a>
<?php } ?>

In this example, if today’s date is no greater than January 1st 2021, the link to the conference will not be available. You can tweak your condition by adding a “less than (<)” condition.

NB: Make sure to backup your theme and database before adding these functions.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>