{"id":628,"date":"2008-09-04T08:45:32","date_gmt":"2008-09-04T16:45:32","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/"},"modified":"2008-09-04T08:45:32","modified_gmt":"2008-09-04T16:45:32","slug":"get-otherdate","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/","title":{"rendered":"Get-OtherDate"},"content":{"rendered":"<p>PowerShell&#8217;s [DATETIME] object has some handy methods for calculating a date such as <strong>AddDays<\/strong>().<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<pre><font color=\"#0000ff\">PS C:\\&gt; get-date\n\nWednesday, September 03, 2008 4:11:18 PM\n\nPS C:\\&gt; (get-date).AddDays(23)\n\nFriday, September 26, 2008 4:11:34 PM\n\nPS C:\\&gt;<\/font><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can even subtract by adding a negative number:<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<pre><font color=\"#0000ff\">PS C:\\&gt; (get-date).AddHours(-67)\n\nSunday, August 31, 2008 9:14:40 PM<\/font>\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The [DATETIME] object also allows you to add a TimeSpan like this:<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<pre><font color=\"#0000ff\">PS C:\\&gt; [datetime]$d=\"2\/22\/2008 5:00AM\"\nPS C:\\&gt; #Add 2 days<br>PS C:\\&gt; $d.Add(\"2:0:0\")\n\nFriday, February 22, 2008 7:00:00 AM\nPS C:\\&gt; #Add 34 minutes\nPS C:\\&gt; $d.Add(\"0:34:0\")\n\nFriday, February 22, 2008 5:34:00 AM\n\nPS C:\\&gt; #Add 15 seconds\nPS C:\\&gt; $d.Add(\"0:0:15\")\n\nFriday, February 22, 2008 5:00:15 AM\n\nPS C:\\&gt; #Add 2 days, 3 hours and 15 min<br>PS C:\\&gt; $d.Add(\"2:3:15\")\n\nFriday, February 22, 2008 7:03:15 AM<\/font><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This is all nice. But what if you wanted to calculate a more complex date time, perhaps one in years? There is an <strong>AddYears()<\/strong> method. Although none of this will help if you want to calculate a date that is 1 year, 2 months&nbsp; and 1 day from now. For those situations, or if you want a simpler approach instead of calling methods, I wrote the <strong><font color=\"#0000ff\">Get-OtherDate<\/font><\/strong> function.<\/p>\n<div style=\"border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4\">\n<div style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\">\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">   1:<\/span> Function Get-OtherDate {<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">   2:<\/span>     Param([datetime]$date=(Get-Date),<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">   3:<\/span>           [int32]$years=0,<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">   4:<\/span>           [int32]$months=0,<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">   5:<\/span>           [int32]$days=0,<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">   6:<\/span>           [int32]$hours=0,<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">   7:<\/span>           [int32]$minutes=0,<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">   8:<\/span>           [int32]$seconds=0,<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">   9:<\/span>           [int32]$milliseconds=0<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  10:<\/span>           )<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  11:<\/span>           <\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  12:<\/span>     [datetime]$dt=$date   <\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  13:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($milliseconds <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddMilliseconds($milliseconds)}<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  14:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($seconds <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddSeconds($seconds)}<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  15:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($minutes <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddMinutes($minutes)}<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  16:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($hours <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddHours($hours)}<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  17:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($days <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddDays($days)}     <\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  18:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($months <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddMonths($months)}<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  19:<\/span>     <span style=\"color: #0000ff\">if<\/span> ($years <span style=\"color: #cc6633\">-ne<\/span> 0) {$dt=$dt.AddYears($years)}<\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  20:<\/span>  <\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  21:<\/span>     write $dt          <\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none\"><span style=\"color: #606060\">  22:<\/span>   <\/pre>\n<pre style=\"padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none\"><span style=\"color: #606060\">  23:<\/span> }<\/pre>\n<\/div>\n<\/div>\n<p>The function takes as parameters a starting date ($date) and then one or more parameters for time intervals such as -days, -hours or -minutes.&nbsp; You don&#8217;t have to specify a starting date, it will default to the current date and time.&nbsp; All the function does is call the appropriate [datetime] method and builds a new date time object moving&nbsp; from the smallest time interval to the largest. Here are some examples of the function in use with the default current date:<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<pre><font color=\"#0000ff\">PS C:\\&gt; get-date\n\nThursday, September 04, 2008 12:15:43 PM\n\nPS C:\\&gt; Get-OtherDate -months 1 -days 11 -hours 7\n\nWednesday, October 15, 2008 7:15:46 PM\n\nPS C:\\&gt; Get-OtherDate -days -45\n\nMonday, July 21, 2008 12:16:08 PM<\/font><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Here are some samples using a different date:<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<pre><font color=\"#0000ff\">PS C:\\&gt; get-OtherDate 7\/4\/2008 -days 99\n\nSaturday, October 11, 2008 12:00:00 AM\n\nPS C:\\&gt; Get-OtherDate 12:34 -hours 4\n\nThursday, September 04, 2008 4:34:00 PM\n\nPS C:\\&gt; Get-OtherDate 22:34 -hours -4 -minutes -14\n\nThursday, September 04, 2008 6:20:00 PM<\/font><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>There&#8217;s nothing really special here.&nbsp; All I&#8217;ve done is create a shortcut function. An advantage is that I can create an alias (like od) and take advantage of short parameter names. Here&#8217;s how this might work in a production environment:<\/p>\n<table border=\"1\">\n<tbody>\n<tr>\n<td>\n<pre><font color=\"#0000ff\">PS C:\\&gt; [ADSI]$admin=\"WinNT:\/\/$env:computername\/Administrator,user\"\nPS C:\\&gt; $lastset = od -s (-$admin.passwordage.value)\nPS C:\\&gt; $expires = od $lastset -day 60\nPS C:\\&gt; Write-host \"Password last set $lastSet and expires $expires\"\nPassword last set 09\/02\/2008 22:29:51 and expires 11\/01\/2008 22:29:51\nPS C:\\&gt;<\/font><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"wlWriterSmartContent\" id=\"scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:f094b7c9-0e3e-48b2-a70c-ca67a4893d90\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">\n<p>Download the script file <a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2008\/09\/get-otherdate.txt\" target=\"_blank\">here<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell&#8217;s [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell&#8217;s methods just aren&#8217;t enough.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[65,281,282,28,57],"class_list":["post-628","post","type-post","status-publish","format-standard","hentry","category-windows-powershell","tag-automation","tag-datetime","tag-functions","tag-powershell","tag-scripting"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"PowerShell&#039;s [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell&#039;s methods just aren&#039;t enough.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Jeffery Hicks\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"DEV SAPIEN Blog - Tools for IT Success\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Get-OtherDate - DEV SAPIEN Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"PowerShell&#039;s [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell&#039;s methods just aren&#039;t enough.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-09-04T16:45:32+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2008-09-04T16:45:32+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Get-OtherDate - DEV SAPIEN Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"PowerShell&#039;s [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell&#039;s methods just aren&#039;t enough.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#blogposting\",\"name\":\"Get-OtherDate - DEV SAPIEN Blog\",\"headline\":\"Get-OtherDate\",\"author\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/author\\\/jeffery-hicks\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/#organization\"},\"datePublished\":\"2008-09-04T08:45:32-07:00\",\"dateModified\":\"2008-09-04T08:45:32-07:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#webpage\"},\"articleSection\":\"Windows PowerShell, automation, DateTime, Functions, powershell, scripting\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/dev.sapien.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/topics\\\/windows-powershell\\\/#listItem\",\"name\":\"Windows PowerShell\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/topics\\\/windows-powershell\\\/#listItem\",\"position\":2,\"name\":\"Windows PowerShell\",\"item\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/topics\\\/windows-powershell\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#listItem\",\"name\":\"Get-OtherDate\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#listItem\",\"position\":3,\"name\":\"Get-OtherDate\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/topics\\\/windows-powershell\\\/#listItem\",\"name\":\"Windows PowerShell\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/#organization\",\"name\":\"DEV SAPIEN Blog\",\"description\":\"Tools for IT Success\",\"url\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/author\\\/jeffery-hicks\\\/#author\",\"url\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/author\\\/jeffery-hicks\\\/\",\"name\":\"Jeffery Hicks\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#webpage\",\"url\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/\",\"name\":\"Get-OtherDate - DEV SAPIEN Blog\",\"description\":\"PowerShell's [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell's methods just aren't enough.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/2008\\\/09\\\/04\\\/get-otherdate\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/author\\\/jeffery-hicks\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/author\\\/jeffery-hicks\\\/#author\"},\"datePublished\":\"2008-09-04T08:45:32-07:00\",\"dateModified\":\"2008-09-04T08:45:32-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/\",\"name\":\"DEV SAPIEN Blog\",\"description\":\"Tools for IT Success\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/dev.sapien.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Get-OtherDate - DEV SAPIEN Blog","description":"PowerShell's [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell's methods just aren't enough.","canonical_url":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#blogposting","name":"Get-OtherDate - DEV SAPIEN Blog","headline":"Get-OtherDate","author":{"@id":"https:\/\/dev.sapien.com\/blog\/author\/jeffery-hicks\/#author"},"publisher":{"@id":"https:\/\/dev.sapien.com\/blog\/#organization"},"datePublished":"2008-09-04T08:45:32-07:00","dateModified":"2008-09-04T08:45:32-07:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#webpage"},"isPartOf":{"@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#webpage"},"articleSection":"Windows PowerShell, automation, DateTime, Functions, powershell, scripting"},{"@type":"BreadcrumbList","@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/dev.sapien.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog\/topics\/windows-powershell\/#listItem","name":"Windows PowerShell"}},{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog\/topics\/windows-powershell\/#listItem","position":2,"name":"Windows PowerShell","item":"https:\/\/dev.sapien.com\/blog\/topics\/windows-powershell\/","nextItem":{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#listItem","name":"Get-OtherDate"},"previousItem":{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#listItem","position":3,"name":"Get-OtherDate","previousItem":{"@type":"ListItem","@id":"https:\/\/dev.sapien.com\/blog\/topics\/windows-powershell\/#listItem","name":"Windows PowerShell"}}]},{"@type":"Organization","@id":"https:\/\/dev.sapien.com\/blog\/#organization","name":"DEV SAPIEN Blog","description":"Tools for IT Success","url":"https:\/\/dev.sapien.com\/blog\/"},{"@type":"Person","@id":"https:\/\/dev.sapien.com\/blog\/author\/jeffery-hicks\/#author","url":"https:\/\/dev.sapien.com\/blog\/author\/jeffery-hicks\/","name":"Jeffery Hicks"},{"@type":"WebPage","@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#webpage","url":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/","name":"Get-OtherDate - DEV SAPIEN Blog","description":"PowerShell's [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell's methods just aren't enough.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/dev.sapien.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/#breadcrumblist"},"author":{"@id":"https:\/\/dev.sapien.com\/blog\/author\/jeffery-hicks\/#author"},"creator":{"@id":"https:\/\/dev.sapien.com\/blog\/author\/jeffery-hicks\/#author"},"datePublished":"2008-09-04T08:45:32-07:00","dateModified":"2008-09-04T08:45:32-07:00"},{"@type":"WebSite","@id":"https:\/\/dev.sapien.com\/blog\/#website","url":"https:\/\/dev.sapien.com\/blog\/","name":"DEV SAPIEN Blog","description":"Tools for IT Success","inLanguage":"en-US","publisher":{"@id":"https:\/\/dev.sapien.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"DEV SAPIEN Blog - Tools for IT Success","og:type":"article","og:title":"Get-OtherDate - DEV SAPIEN Blog","og:description":"PowerShell's [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell's methods just aren't enough.","og:url":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/","article:published_time":"2008-09-04T16:45:32+00:00","article:modified_time":"2008-09-04T16:45:32+00:00","twitter:card":"summary_large_image","twitter:title":"Get-OtherDate - DEV SAPIEN Blog","twitter:description":"PowerShell's [DATETIME] object has some handy methods for calculating a date such as AddDays(). Let me show you how as well as my own function for those situations where PowerShell's methods just aren't enough."},"aioseo_meta_data":{"post_id":"628","title":null,"description":null,"keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-08-28 14:28:52","updated":"2026-08-28 14:28:52"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/dev.sapien.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/dev.sapien.com\/blog\/topics\/windows-powershell\/\" title=\"Windows PowerShell\">Windows PowerShell<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGet-OtherDate\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/dev.sapien.com\/blog"},{"label":"Windows PowerShell","link":"https:\/\/dev.sapien.com\/blog\/topics\/windows-powershell\/"},{"label":"Get-OtherDate","link":"https:\/\/dev.sapien.com\/blog\/2008\/09\/04\/get-otherdate\/"}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=628"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}