{"id":4185,"date":"2020-04-25T10:41:31","date_gmt":"2020-04-25T14:41:31","guid":{"rendered":"https:\/\/themespress.ca\/?p=4185"},"modified":"2021-11-23T10:41:30","modified_gmt":"2021-11-23T15:41:30","slug":"comparing-dates-prompt-message","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/comparing-dates-prompt-message\/","title":{"rendered":"Display a Message When Comparing Two Dates"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>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.<\/p>\n<p>For example, you want to define a <strong>condition that today&#8217;s date<\/strong> is <strong>less than<\/strong> the date from a dynamic result.<\/p>\n<p>We will need to generate our dates in a specific format (Date : 01-01-20 for our current example) with <a href=\"https:\/\/www.php.net\/manual\/en\/function.strtotime.php\" target=\"_blank\" rel=\"noopener noreferrer\">strtotime<\/a>. To generate the current day&#8217;s date we will use <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/get_the_date\/\" target=\"_blank\" rel=\"noopener noreferrer\">get_the_date(format)<\/a>.<\/p>\n<p>Here is the condition:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9219674\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-9219674\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"custom\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php \n$datetoday = strtotime(get_the_date(&#039;d-m-y&#039;)); \n$dateconference = &#039;01-01-21&#039;; \n\nif ( ( $datetoday &gt; $dateconference) ) { ?&gt;\n&lt;?php echo &#039;Disponible prochainement&#039;; ?&gt;\t \n&lt;?php } else { ?&gt;\n&lt;a href=&quot;&quot; class=&quot;bouton-print&quot;&gt;&lt;?php _e(&#039;Remplir&#039;, &#039;nomdevotretheme&#039;); ?&gt;&lt;\/a&gt;\n&lt;?php } ?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p> In this example, if today&#8217;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 &#8220;less than (&lt;)&#8221; condition.<\/p>\n<p><strong>NB: Make sure to backup your theme and database before adding these functions.<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"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<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/comparing-dates-prompt-message\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4921,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[320],"class_list":["post-4185","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-php-coding"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=4185"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4185\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4921"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=4185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=4185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=4185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}