{"id":85929,"date":"2004-08-27T12:04:29","date_gmt":"2004-08-27T20:04:29","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/scripting\/?p=85929"},"modified":"2019-06-03T12:34:08","modified_gmt":"2019-06-03T20:34:08","slug":"how-can-i-determine-the-day-of-the-week","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-the-day-of-the-week\/","title":{"rendered":"How Can I Determine the Day of the Week?"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2005\/08\/q-for-powertip.jpg\" alt=\"question\" width=\"34\" height=\"34\" class=\"alignleft size-full wp-image-83488\" \/><\/p>\n<p>Hey, Scripting Guy! I have a script that does certain management tasks based on the day of the week. I know how get the date in a script, but how can I tell whether it\u2019s a Monday or a Tuesday or whatever?<\/p>\n<p>&#8212; CT, Tallahassee, FL<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"\" width=\"5\" height=\"5\" class=\"alignright size-full wp-image-85925\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"answer\" width=\"34\" height=\"34\" class=\"alignleft size-full wp-image-83488\" \/>\n<img decoding=\"async\" src=\"http:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" alt=\"\" width=\"5\" height=\"5\" class=\"alignright size-full wp-image-85925\" \/><\/p>\n<p><!--<a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" alt=\"Script Center\" width=\"120\" height=\"288\" align=\"right\" border=\"0\" \/><\/a>--><\/p>\n<p>Hey, CT. This is actually much easier then it might sound; that\u2019s because VBScript has a built-in function called DatePart that can take any date you give it and tell you everything from the hour to the minute to the day of the week. All you have to do is pass DatePart two items:<\/p>\n<table id=\"EYC\" class=\"dataTable\" cellspacing=\"0\" cellpadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" valign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>The date part you\u2019re looking for.<\/b><\/p>\n<\/td>\n<td style=\"border-right: #cccccc 1px solid;\">\n<p class=\"lastInCell\">In this case, we\u2019re looking for the day of the week, so we pass the value \u201cw\u201d. If we were looking for, say, the year, we\u2019d pass the value \u201cy\u201d.<\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" valign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>The date in question.<\/b><\/p>\n<\/td>\n<td style=\"border-right: #cccccc 1px solid;\">\n<p class=\"lastInCell\">For this script, we simply assign the current date to the variable dtmToday.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>Our script ends up looking something like this:<\/p>\n<pre class=\"codeSample\">dtmToday = Date()\r\n\r\ndtmDayOfWeek = DatePart(\"w\", dtmToday)\r\n\r\nSelect Case dtmDayOfWeek\r\n    Case 1 Wscript.Echo \"Sunday\"\r\n    Case 2 Wscript.Echo \"Monday\"\r\n    Case 3 Wscript.Echo \"Tuesday\"\r\n    Case 4 Wscript.Echo \"Wednesday\"\r\n    Case 5 Wscript.Echo \"Thursday\"\r\n    Case 6 Wscript.Echo \"Friday\"\r\n    Case 7 Wscript.Echo \"Saturday\"\r\nEnd Select\r\n<\/pre>\n<p>Note the one tricky part: the day of the week comes back as an integer (1 = Sunday, 2 = Monday, etc.). Therefore, for the purposes of <i>this<\/i> script we used a Select Case statement to convert that integer into the actual day of the week itself.<\/p>\n<p>For more information about the DatePart function, see this portion of the <a href=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee692931.aspx\" target=\"_blank\" rel=\"noopener\">Microsoft Windows 2000 Scripting Guide<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I have a script that does certain management tasks based on the day of the week. I know how get the date in a script, but how can I tell whether it\u2019s a Monday or a Tuesday or whatever? &#8212; CT, Tallahassee, FL Hey, CT. This is actually much easier then it [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[162,56,597,650,3,45],"class_list":["post-85929","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-boe-prox","tag-guest-blogger","tag-module","tag-runspace","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I have a script that does certain management tasks based on the day of the week. I know how get the date in a script, but how can I tell whether it\u2019s a Monday or a Tuesday or whatever? &#8212; CT, Tallahassee, FL Hey, CT. This is actually much easier then it [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85929","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=85929"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/85929\/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=85929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=85929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=85929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}