{"id":4221,"date":"2021-11-08T16:54:50","date_gmt":"2021-11-08T22:54:50","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=4221"},"modified":"2021-11-08T16:54:50","modified_gmt":"2021-11-08T22:54:50","slug":"how-to-find-yesterdays-date-in-linux","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/how-to-find-yesterdays-date-in-linux\/","title":{"rendered":"How to Find Yesterdays Date in Linux"},"content":{"rendered":"\n<p><strong>The wrong way to find yesterdays date:<\/strong><\/p>\n\n\n\n<p>I had a command that was used to see if.  It used some arithmetic operators to subtract 1 from the current day.  That would give us yesterdays day which we could then use to check if a backup was created then.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">day=$(date +%d) ; date=$(($day - 1)) ; echo \"yesterday date is $date\"<\/pre>\n\n\n\n<p>It worked great, unless you happened to be on the 8th or 9th of the month.  Looks like bash is interpreting 08 and 09 in octal format.  <a href=\"https:\/\/stackoverflow.com\/questions\/24777597\/value-too-great-for-base-error-token-is-08\">https:\/\/stackoverflow.com\/questions\/24777597\/value-too-great-for-base-error-token-is-08<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">-bash: 08: value too great for base (error token is \"08\")<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>The better way<\/strong><\/p>\n\n\n\n<p>Fortunately there is an easier and more reliable way to do this.  Using the date command, you can specify yesterday and it will print out yesterdays date.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">date --date=yesterday +%d<\/pre>\n\n\n\n<p>Much easier to use.<\/p>\n\n\n\n<p>Some more info.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.cyberciti.biz\/tips\/linux-unix-get-yesterdays-tomorrows-date.html?cf_chl_captcha_tk=N9iBfod_b0qUxjB2jIGlETgiZ.JXSxGpLmvQ83CzBvY-1636407896-0-gaNycGzNBmU\">https:\/\/www.cyberciti.biz\/tips\/linux-unix-get-yesterdays-tomorrows-date.html?cf_chl_captcha_tk=N9iBfod_b0qUxjB2jIGlETgiZ.JXSxGpLmvQ83CzBvY-1636407896-0-gaNycGzNBmU<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/18180581\/subtract-days-from-a-date-in-bash\">https:\/\/stackoverflow.com\/questions\/18180581\/subtract-days-from-a-date-in-bash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The wrong way to find yesterdays date: I had a command that was used to see if. It used some arithmetic operators to subtract 1 from the current day. That would give us yesterdays day which we could then use &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/how-to-find-yesterdays-date-in-linux\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[211,7,606],"class_list":["post-4221","post","type-post","status-publish","format-standard","hentry","category-linux","tag-bash","tag-linux-2","tag-programming"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=4221"}],"version-history":[{"count":1,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4221\/revisions"}],"predecessor-version":[{"id":4222,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/4221\/revisions\/4222"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=4221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=4221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=4221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}