{"id":7059,"date":"2019-01-01T12:35:53","date_gmt":"2019-01-01T12:35:53","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=7059"},"modified":"2019-01-08T10:16:43","modified_gmt":"2019-01-08T10:16:43","slug":"how-to-count-days-since-a-specific-date-until-today-using-bash-shell","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/01\/how-to-count-days-since-a-specific-date-until-today-using-bash-shell\/","title":{"rendered":"How to count days since a specific date until today using Bash shell ?"},"content":{"rendered":"<p>The easiest way to perform days count since a specifics day is to first get a number of seconds<\/p>\n<p>since epoch time ( 1970-01-01 ) for both dates. As an example let\u2019s count number of days<\/p>\n<p>since 28.12.1999 until today 8.1.2018. Consider a following example:<\/p>\n<p>$ echo $((($(date +%s)-$(date +%s &#8211;date &#8220;1999-12-28&#8221;))\/(3600*24))) days<br \/>\n6586 days<\/p>\n<p>Let&#8217;s add little bit of readability to the above command by using variables. First, we get<\/p>\n<p>seconds since epoch time ( 1970-01-01 ) until now:<\/p>\n<p>$ now=$(date +%s)<\/p>\n<p>$ echo $now<br \/>\n1515370378<\/p>\n<p>Next we do the same for the 28.12.1999 date:<\/p>\n<p>past=$(date +%s &#8211;date &#8220;1999-12-28&#8221;)<br \/>\n$ echo $past<br \/>\n946299600<\/p>\n<p>Next, calculate the difference:<\/p>\n<p>$ difference=$(($now-$past))<br \/>\n$ echo $difference<br \/>\n569070778<\/p>\n<p>Lastly, convert the difference in seconds to days:<br \/>\n$ echo $(($difference\/(3600*24)))<br \/>\n6586<\/p>\n<p>All done. The same principle can be used to calculate days between any specific days.<\/p>\n<p>For example let&#8217;s count days between 1.1.2016 and 31.12.2016 dates:<\/p>\n<p>$ echo $((($(date +%s &#8211;date &#8220;2016-12-31&#8221;)-$(date +%s &#8211;date &#8220;2016-1-1&#8221;))\/(3600*24))) days<br \/>\n365 days<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.linuxforfreshers.com\/2019\/01\/how-to-count-days-since-specific-date.html\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The easiest way to perform days count since a specifics day is to first get a number of seconds since epoch time ( 1970-01-01 ) for both dates. As an example let\u2019s count number of days since 28.12.1999 until today 8.1.2018. Consider a following example: $ echo $((($(date +%s)-$(date +%s &#8211;date &#8220;1999-12-28&#8221;))\/(3600*24))) days 6586 days &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/01\/how-to-count-days-since-a-specific-date-until-today-using-bash-shell\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to count days since a specific date until today using Bash shell ?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7059","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7059","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=7059"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7059\/revisions"}],"predecessor-version":[{"id":7383,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/7059\/revisions\/7383"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=7059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=7059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=7059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}