{"id":71733,"date":"2004-08-03T12:02:00","date_gmt":"2004-08-03T12:02:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/08\/03\/how-can-i-get-yesterdays-date\/"},"modified":"2004-08-03T12:02:00","modified_gmt":"2004-08-03T12:02:00","slug":"how-can-i-get-yesterdays-date","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-yesterdays-date\/","title":{"rendered":"How Can I Get Yesterday&#8217;s Date?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p>Hey, Scripting Guy! I\u2019m writing a script, and I need to know <i>yesterday\u2019s<\/i> date. I can use Date() to figure out today\u2019s date, but how do I figure out yesterday\u2019s date?<\/p>\n<p>&#8212; SS<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/a><\/p>\n<p>Hey, SS. You\u2019re right; it\u2019s easy to determine today\u2019s date using a script:<\/p>\n<pre class=\"codeSample\">dtmToday = Date()\nWscript.Echo dtmToday\n<\/pre>\n<p>But what about yesterday\u2019s date? Listen, we\u2019ve got good news for you: it\u2019s just as easy to determine yesterday\u2019s date as it is today\u2019s date. That\u2019s because VBScript can do date arithmetic: give it today\u2019s date, and then you can simply subtract 1 day to determine yesterday\u2019s date. In other words:<\/p>\n<pre class=\"codeSample\">dtmYesterday = Date() - 1\nWscript.Echo dtmYesterday\n<\/pre>\n<p>Want to know tomorrow\u2019s date? You\u2019re way ahead of us:<\/p>\n<pre class=\"codeSample\">dtmTomorrow = Date() + 1\nWscript.Echo dtmTomorrow\n<\/pre>\n<p>Cool, huh? Incidentally, you can do even fancier date arithmetic using VBScript. Want to know the date that\u2019s 37 days from July 30, 2004? You can calculate that using the DateAdd function:<\/p>\n<pre class=\"codeSample\">dtmDate = DateAdd(\"d\", 37, \"July 30, 2004\")\nWscript.Echo dtmDate\n<\/pre>\n<p>For more information about the DateAdd function, see this portion of the <a href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_vbs.mspx\" target=\"_blank\">Microsoft Windows 2000 Scripting Guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I\u2019m writing a script, and I need to know yesterday\u2019s date. I can use Date() to figure out today\u2019s date, but how do I figure out yesterday\u2019s date? &#8212; SS Hey, SS. You\u2019re right; it\u2019s easy to determine today\u2019s date using a script: dtmToday = Date() Wscript.Echo dtmToday But what about yesterday\u2019s [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[13,3,4,5],"class_list":["post-71733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-dates-and-times","tag-scripting-guy","tag-scripting-techniques","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I\u2019m writing a script, and I need to know yesterday\u2019s date. I can use Date() to figure out today\u2019s date, but how do I figure out yesterday\u2019s date? &#8212; SS Hey, SS. You\u2019re right; it\u2019s easy to determine today\u2019s date using a script: dtmToday = Date() Wscript.Echo dtmToday But what about yesterday\u2019s [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=71733"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71733\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=71733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}