{"id":6822,"date":"2016-05-29T16:15:05","date_gmt":"2016-05-29T08:15:05","guid":{"rendered":"http:\/\/onthe8spot.com\/?p=6822"},"modified":"2016-05-29T16:15:05","modified_gmt":"2016-05-29T08:15:05","slug":"datetime-in-a-unix-shell-how-to-get-yesterdays-date-into-a-variable-stack-overflow","status":"publish","type":"post","link":"http:\/\/onthe8spot.com\/index.php\/2016\/05\/29\/datetime-in-a-unix-shell-how-to-get-yesterdays-date-into-a-variable-stack-overflow\/","title":{"rendered":"datetime &#8211; In a unix shell, how to get yesterday&#039;s date into a variable? &#8211; Stack Overflow"},"content":{"rendered":"<blockquote><p>In a unix shell, how to get yesterday&#8217;s date into a variable?<\/p>\n<table>\n<tbody>\n<tr>\n<td class=\"answercell\">\n<div class=\"post-text\">\n<strong>You can use GNU date command as shown below<\/strong><\/p>\n<blockquote><p>Getting Date In the Past<br \/>\nTo get yesterday and earlier day in the past use string day ago:<\/p><\/blockquote>\n<p>date &#8211;date=&#8217;yesterday&#8217;<br \/>\ndate &#8211;date=&#8217;1 day ago&#8217;<br \/>\ndate &#8211;date=&#8217;10 day ago&#8217;<br \/>\ndate &#8211;date=&#8217;10 week ago&#8217;<br \/>\ndate &#8211;date=&#8217;10 month ago&#8217;<br \/>\ndate &#8211;date=&#8217;10 year ago&#8217;<\/p>\n<blockquote><p>Getting Date In the Future<br \/>\nTo get tomorrow and day after tomorrow (tomorrow+N) use day word to get date in the future as follows:<\/p><\/blockquote>\n<p>date &#8211;date=&#8217;tomorrow&#8217;<br \/>\ndate &#8211;date=&#8217;1 day&#8217;<br \/>\ndate &#8211;date=&#8217;10 day&#8217;<br \/>\ndate &#8211;date=&#8217;10 week&#8217;<br \/>\ndate &#8211;date=&#8217;10 month&#8217;<br \/>\ndate &#8211;date=&#8217;10 year&#8217;\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/blockquote>\n<p>Source: <em><a href=\"http:\/\/stackoverflow.com\/questions\/3517982\/in-a-unix-shell-how-to-get-yesterdays-date-into-a-variable\">datetime &#8211; In a unix shell, how to get yesterday&#8217;s date into a variable? &#8211; Stack Overflow<\/a><\/em><br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\nI basically google everything when making a shell script for linux. \u00a0Blame projects with component that require windows stuff which has helped me forget what I used to know about shell scripting<br \/>\n&nbsp;<br \/>\nHere is a way of using GNU date which is fortunately present in the linux installed in the oracle servers where our weblogic application servers are installed.<br \/>\nThis was used in a CRON job that had to look at a file that is stored in a directory which is formatted with yesterday&#8217;s date &lt;YYYYMMDD&gt;.<br \/>\nanother useful <a href=\"http:\/\/stackoverflow.com\/questions\/18458839\/how-to-get-the-current-date-and-time-in-the-terminal-and-set-a-custom-command-in\">stackoverflow link regarding the date command<\/a>.<br \/>\nHere is the <a href=\"http:\/\/unix.stackexchange.com\/questions\/8584\/using-the-system-date-time-in-a-cron-script\">link\u00a0that help me format the command in a CRON job<\/a><br \/>\nThe secret is that <strong>%<\/strong> have to be escaped with <strong>\\<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a unix shell, how to get yesterday&#8217;s date into a variable? You can use GNU date command as shown below Getting Date In the Past To get yesterday and earlier day in the past use string day ago: date &#8211;date=&#8217;yesterday&#8217; date &#8211;date=&#8217;1 day ago&#8217; date &#8211;date=&#8217;10 day ago&#8217; date &#8211;date=&#8217;10 week ago&#8217; date &#8211;date=&#8217;10 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/onthe8spot.com\/index.php\/2016\/05\/29\/datetime-in-a-unix-shell-how-to-get-yesterdays-date-into-a-variable-stack-overflow\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;datetime &#8211; In a unix shell, how to get yesterday&#039;s date into a variable? &#8211; Stack Overflow&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18],"tags":[],"class_list":["post-6822","post","type-post","status-publish","format-standard","hentry","category-coding"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts\/6822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/comments?post=6822"}],"version-history":[{"count":0,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/posts\/6822\/revisions"}],"wp:attachment":[{"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/media?parent=6822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/categories?post=6822"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/onthe8spot.com\/index.php\/wp-json\/wp\/v2\/tags?post=6822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}