{"id":5727,"date":"2022-02-24T10:22:31","date_gmt":"2022-02-24T15:22:31","guid":{"rendered":"https:\/\/themespress.ca\/?p=5727"},"modified":"2022-03-24T08:10:50","modified_gmt":"2022-03-24T12:10:50","slug":"calculate-the-number-of-days-between-two-dates","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/calculate-the-number-of-days-between-two-dates\/","title":{"rendered":"Calculate the Number of Days between 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 calculate the number of days between two dates. And with our example, We will also see an example of mathematical calculation with a <a href=\"https:\/\/shareasale.com\/r.cfm?b=841990&amp;u=1476870&amp;m=64739&amp;urllink=&amp;afftrack=\"><strong>Formidable form<\/strong><\/a> shortcode.<\/p>\n<p>Let&#8217;s create a shortcode to calculate the number of days.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Calculate the number of days between two dates<\/h2><div id=\"ts-enlighterjs-container-8539219\" 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-8539219\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">function themespress_numberdays_shortcode() { \n     $now = time(); \/\/ Current time \n     $your_date = strtotime(&#039;2022-01-23&#039;); \/\/ The first date\n     $datediff = abs($now - $your_date); \/\/ Gives absolute Value \n     return floor($datediff\/(60*60*24)); \/\/ Returns the lowest value by rounding down value \n} \n\/\/ register shortcode\nadd_shortcode(&#039;numberdays&#039;, &#039;themespress_numberdays_shortcode&#039;); <\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p><strong>Our date &#8216;<span class=\"st0\">2022-01-23&#8242;<\/span> <\/strong> will be the start date and the variable <strong>$now<\/strong> represents the current time. Afterwards, we need to <strong>calculate the number of days between two dates.<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div class=\"vc_row wpb_row vc_inner 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>We can do calculations and statistics with the following Formidable Form shortcode:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div><div id=\"ts-enlighterjs-container-9487164\" 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-9487164\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">[frm-math][\/frm-math]<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this mathematical shortcode, we will insert the data to calculate. For example, we want to calculate the daily grocery expenses between two dates.<\/p>\n<p>For example, you can create a Formidable Form to include grocery expenses.<\/p>\n<p>Form fields:<\/p>\n<p>1 &#8211; A hidden field with the default value of the date where the entry was created [date]<\/p>\n<p>2 &#8211; Select Options field with various grocery stores (Ex: Costco, Walmart, etc&#8230;)<\/p>\n<p>3 &#8211; A number field with the amount<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div  class=\"wpb_single_image wpb_content_element vc_align_left wpb_content_element\">\n\t\t\n\t\t<figure class=\"wpb_wrapper vc_figure\">\n\t\t\t<div class=\"vc_single_image-wrapper   vc_box_border_grey\"><img decoding=\"async\" width=\"1434\" height=\"541\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire.png\" class=\"vc_single_image-img attachment-full\" alt=\"Formidable Form - Exemple formulaire\" title=\"Formidable Form - Exemple formulaire\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire.png 1434w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire-600x226.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire-300x113.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire-1024x386.png 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire-768x290.png 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Formidable-Form-Exemple-formulaire-1320x498.png 1320w\" sizes=\"(max-width: 1434px) 100vw, 1434px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p> After adding some data, you can proceed with the calculation with two shortcodes:<\/p>\n<p>1 &#8211; We want to obtain the amount total (with entry ID) that will be the ID of my amount field.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2685317\" 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-2685317\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/ Remplacez 321 par l&#039;ID de votre entr&eacute;e montant.\n[frm-stats id=321 type=total]<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>2 &#8211; The shortcode for which calculates the number of days with the function created above. [numberdays].<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9010835\" 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-9010835\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/ Fonction de notre calcul du nombre de jours.\n[numberdays]<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Now, calculate the results on one of your pages:<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-7251980\" 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-7251980\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/ Remplacez 321 par l&#039;ID de votre entr&eacute;e montant.\n[frm-math][frm-stats id=321 type=total] \/ [numberdays][\/frm-math]<\/pre><\/div><div class=\"vc_row wpb_row vc_inner 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 Formidable Form, you can generate charts to display your results.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div  class=\"wpb_single_image wpb_content_element vc_align_left wpb_content_element\">\n\t\t\n\t\t<figure class=\"wpb_wrapper vc_figure\">\n\t\t\t<div class=\"vc_single_image-wrapper   vc_box_border_grey\"><img decoding=\"async\" width=\"900\" height=\"400\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Exemple-de-graphique-formidable-form.png\" class=\"vc_single_image-img attachment-full\" alt=\"Exemple de graphique formidable form\" title=\"Exemple de graphique formidable form\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Exemple-de-graphique-formidable-form.png 900w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Exemple-de-graphique-formidable-form-600x267.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Exemple-de-graphique-formidable-form-300x133.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/02\/Exemple-de-graphique-formidable-form-768x341.png 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2477137\" 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-2477137\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/ Remplacez 320 par l&#039;ID du champ select options des supermarch&eacute;s\n[frm-graph fields=&quot;320&quot; type=&quot;column&quot; data_type=&quot;total&quot;]<\/pre><\/div>\n\t<div class=\"wpb_raw_code wpb_raw_html wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<a class=\"read-more\" href=\"https:\/\/formidableforms.com\/knowledgebase\/graphs\/\">Les graphiques Formidable Form<\/a>\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you how to calculate the number of days between two dates. And with our example, We will also see an example of mathematical calculation<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/calculate-the-number-of-days-between-two-dates\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":5728,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[351],"class_list":["post-5727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-forms"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5727","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=5727"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5727\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/5728"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=5727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=5727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=5727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}