{"id":2951,"date":"2013-04-12T12:52:11","date_gmt":"2013-04-12T16:52:11","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2951"},"modified":"2013-04-16T08:47:32","modified_gmt":"2013-04-16T12:47:32","slug":"friday-fun-get-anniversary","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/","title":{"rendered":"Friday Fun: Get-Anniversary"},"content":{"rendered":"<p>Recently I celebrated a wedding anniversary. Even though I didn't forget I could have used a little help. So I figured since I'm in PowerShell all the time anyway, it could help. I built a little script to remind me of important dates. Let me walk you through the key steps.<\/p>\n<p>First, I'll define a variable for the anniversary date.<\/p>\n<pre class=\"lang:ps decode:true\">[datetime]$anndate=\"5\/6\/2007\"<\/pre>\n<p>I picked a date coming up. Next, it isn't too difficult to calculate the number of days between two dates. But what I needed to do is find May 6th for this year. Here's how I did it:<\/p>\n<pre class=\"lang:ps decode:true\">[datetime]$thisYear = \"$($anndate.month)\/$($anndate.day)\"<\/pre>\n<p>$thisYear is now May 6, 2013. Excellent, because now I can get the number of days until that date.<\/p>\n<pre class=\"lang:ps decode:true\">$when = $thisYear - (Get-Date)<\/pre>\n<p>$when is a TimeSpan object.<\/p>\n<pre class=\"lang:ps decode:true\">Days              : 23\r\nHours             : 11\r\nMinutes           : 25\r\nSeconds           : 42\r\nMilliseconds      : 300\r\nTicks             : 20283423003384\r\nTotalDays         : 23.4761840316944\r\nTotalHours        : 563.428416760667\r\nTotalMinutes      : 33805.70500564\r\nTotalSeconds      : 2028342.3003384\r\nTotalMilliseconds : 2028342300.3384<\/pre>\n<p>I can use the Days property in my message. Although the other item of information I wanted is the number of years for the anniversary. Very important. Again, because we're working with objects all I need to do is subtract the Year properties between the anniversary date and today.<\/p>\n<pre class=\"lang:ps decode:true\">$NumYears = (Get-Date).year - $anndate.Year<\/pre>\n<p>At this point I could simply display a message that tells me how many days are remaining until anniversary #X. But let's go a step further. How about displaying the number of years as an ordinal? For example, 5th or 23rd anniversary. To do that I did a quick search to see if someone had already figured this out, since there is no .NET specific method to accomplish this. I found some code samples and converted them into a PowerShell function.<\/p>\n<pre class=\"lang:ps decode:true\">Function Get-Ordinal {\r\n\r\nParam([int]$i)\r\n\r\nSwitch ($i %100) {\r\n #handle special cases\r\n 11 {$sfx = \"th\" } \r\n 12 {$sfx = \"th\" } \r\n 13 {$sfx = \"th\" } \r\n default {\r\n    Switch ($i % 10) {\r\n        1  { $sfx = \"st\" }\r\n        2  { $sfx = \"nd\" }\r\n        3  { $sfx = \"rd\" }\r\n        default { $sfx = \"th\" }\r\n    } #inner switch\r\n } #default\r\n} #outerswitch\r\n #write the result to the pipeline\r\n \"$i$sfx\"\r\n} #end Get-Ordinal<\/pre>\n<p>Basically you take the number and perform a modulo operation. Based on the result I know what suffix to use and the function writes the ordinal string to the pipeline, like 1st or 7th. \u00a0With that, all that is left to do is display my message.<\/p>\n<pre class=\"lang:ps decode:true\">$msg = \"Your {0} anniversary is in {1} days.\" -f (Get-Ordinal $NumYears),$when.Days<\/pre>\n<p>Let me show you the complete script.<\/p>\n<pre class=\"lang:ps decode:true\">Param (\r\n#what is the anniversary date\r\n[datetime]$anndate=\"5\/6\/2007\"\r\n)\r\n\r\n#a function to create ordinal numbers\r\nFunction Get-Ordinal {\r\n\r\nParam([int]$i)\r\n\r\nSwitch ($i %100) {\r\n #handle special cases\r\n 11 { $sfx = \"th\" } \r\n 12 { $sfx = \"th\" } \r\n 13 { $sfx = \"th\" } \r\n default {\r\n    Switch ($i % 10) {\r\n        1  { $sfx = \"st\" }\r\n        2  { $sfx = \"nd\" }\r\n        3  { $sfx = \"rd\" }\r\n        default { $sfx = \"th\"}\r\n    } #inner switch\r\n } #default\r\n} #outerswitch\r\n #write the result to the pipeline\r\n \"$i$sfx\"\r\n} #end Get-Ordinal\r\n\r\n#how many years\r\n$NumYears = (Get-Date).year - $anndate.Year\r\n\r\n#create the anniversary date for this year\r\n[datetime]$thisYear = \"$($anndate.month)\/$($anndate.day)\"\r\n\r\n#is anniversary next year?\r\nif ($thisYear -lt (Get-Date)) {\r\n  #add a year\"\r\n  $thisYear=$thisYear.AddYears(1)\r\n  $NumYears++\r\n}\r\n\r\n#how soon is the anniversary?\r\n$when = $thisYear - (Get-Date)\r\n\r\n#define an empty hashtable for parameters\r\n$phash = @{}\r\n\r\nif ($when.Days -gt 0) {\r\n  $msg = \"Your {0} anniversary is in {1} days.\" -f (Get-Ordinal $NumYears),$when.Days\r\n  $phash.Add(\"Object\",$msg)\r\n  $phash.Add(\"Foregroundcolor\",\"Green\")\r\n}\r\nelse {\r\n  $msg = \"Your {0} anniversary is in {1} hours and {2} minutes!\" -f (Get-Ordinal $NumYears),$when.hours,$when.minutes\r\n  $phash.Add(\"object\",$msg)\r\n  $phash.Add(\"Foregroundcolor\",\"Red\")\r\n  #Find a florist!!\r\n  start \"http:\/\/www.google.com\/#hl=en&amp;output=search&amp;q=florist\"\r\n}\r\n\r\nWrite-Host @phash<\/pre>\n<p>The only other special feature of this script is that if the number of days is greater than one, the message is display using Write-Host in green.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2954\" alt=\"get-anniversary\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png\" width=\"602\" height=\"163\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png 602w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary-300x81.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n<p>BUT, if you are down to 1 day or less you get the message in red AND your browser will open up to a Google search for Florists. I'm trying to help you out as much as I can. You could call this script from your PowerShell profile and (hopefully) never forget another anniversary or important date. Or you might simply take away some tidbits about datetime objects, timespans and splatting. Either way I think you come out ahead.<\/p>\n<p>Enjoy.<\/p>\n<p><strong>UPDATE April 16, 2013<\/strong><br \/>\nI realized my original code had a problem: if the anniversary date was next year you would get a negative result. For example if the anniversary was yesterday, the script would say your anniversary was in -1 days. That won't work. So I added some code to test the anniversary date compared to the current date. If it is less than today, meaning it has already passed, then I need to add a year.<\/p>\n<pre class=\"lang:ps decode:true \">if ($thisYear -lt (Get-Date)) {\r\n  #add a year\"\r\n  $thisYear=$thisYear.AddYears(1)\r\n  $NumYears++\r\n}<\/pre>\n<p>Now when I calculate the difference between $thisYear and today, I'll get a positive number. I suppose I should rename the variables because $thisYear, in this case, is actually the date for the anniversary next year. I'm also incrementing the value of the number of years is updated.<\/p>\n<p>The other thing to take away from this, and something that I neglected to do (shame on me) is to test based on data that will fail as well as succeed. For this script, I neglected to test for dates that have already passed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I celebrated a wedding anniversary. Even though I didn&#8217;t forget I could have used a little help. So I figured since I&#8217;m in PowerShell all the time anyway, it could help. I built a little script to remind me of important dates. Let me walk you through the key steps. First, I&#8217;ll define a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[271,4],"tags":[568,125,534],"class_list":["post-2951","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","tag-friday-fun","tag-get-date","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun: Get-Anniversary &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun: Get-Anniversary &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Recently I celebrated a wedding anniversary. Even though I didn&#039;t forget I could have used a little help. So I figured since I&#039;m in PowerShell all the time anyway, it could help. I built a little script to remind me of important dates. Let me walk you through the key steps. First, I&#039;ll define a...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-04-12T16:52:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-04-16T12:47:32+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun: Get-Anniversary\",\"datePublished\":\"2013-04-12T16:52:11+00:00\",\"dateModified\":\"2013-04-16T12:47:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/\"},\"wordCount\":591,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-anniversary.png\",\"keywords\":[\"Friday Fun\",\"Get-Date\",\"PowerShell\"],\"articleSection\":[\"Friday Fun\",\"PowerShell\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/\",\"name\":\"Friday Fun: Get-Anniversary &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-anniversary.png\",\"datePublished\":\"2013-04-12T16:52:11+00:00\",\"dateModified\":\"2013-04-16T12:47:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#primaryimage\",\"url\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-anniversary.png\",\"contentUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/04\\\/get-anniversary.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2951\\\/friday-fun-get-anniversary\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun: Get-Anniversary\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun: Get-Anniversary &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun: Get-Anniversary &#8226; The Lonely Administrator","og_description":"Recently I celebrated a wedding anniversary. Even though I didn't forget I could have used a little help. So I figured since I'm in PowerShell all the time anyway, it could help. I built a little script to remind me of important dates. Let me walk you through the key steps. First, I'll define a...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-04-12T16:52:11+00:00","article_modified_time":"2013-04-16T12:47:32+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun: Get-Anniversary","datePublished":"2013-04-12T16:52:11+00:00","dateModified":"2013-04-16T12:47:32+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/"},"wordCount":591,"commentCount":4,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png","keywords":["Friday Fun","Get-Date","PowerShell"],"articleSection":["Friday Fun","PowerShell"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/","name":"Friday Fun: Get-Anniversary &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png","datePublished":"2013-04-12T16:52:11+00:00","dateModified":"2013-04-16T12:47:32+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#primaryimage","url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png","contentUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/get-anniversary.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2951\/friday-fun-get-anniversary\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun: Get-Anniversary"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3377,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3377\/friday-fun-get-day-of-the-year-with-powershell\/","url_meta":{"origin":2951,"position":0},"title":"Friday Fun: Get Day of the Year with PowerShell","author":"Jeffery Hicks","date":"August 30, 2013","format":false,"excerpt":"Earlier this week I was having some fun with @EnergizedTech on Twitter, playing around with dates in PowerShell. I'm not even sure where we started but the experience got me thinking and it's Friday so let's have some fun. While I can easily find out what the day of the\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"calendar","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/08\/calendar.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3374,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3374\/friday-fun-get-friday-the-13th\/","url_meta":{"origin":2951,"position":1},"title":"Friday Fun: Get Friday the 13th","author":"Jeffery Hicks","date":"September 13, 2013","format":false,"excerpt":"I thought it might be fun today to use PowerShell to discover all the Friday the 13ths in a given year. So I put together a simple PowerShell one-liner. To make it flexible I'll use a variable for the year, using the current year as my value. $year = (Get-date).Year\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":976,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/976\/friday-fun-more-prompts\/","url_meta":{"origin":2951,"position":2},"title":"Friday Fun &#8211; More Prompts","author":"Jeffery Hicks","date":"October 22, 2010","format":false,"excerpt":"Not too long ago I offered up a tasting of PowerShell prompts 3 ways. My first offering were variations on displaying the current date and time. But a PowerShell prompt can do much more. For today's Friday Fun I present a duo of of calculating prompts. The first item on\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2010\/10\/timetogo-prompt-300x142.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":8357,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8357\/friday-fun-counting-down-events-with-powershell\/","url_meta":{"origin":2951,"position":3},"title":"Friday Fun: Counting Down Events with PowerShell","author":"Jeffery Hicks","date":"April 30, 2021","format":false,"excerpt":"We just finished a very successful virtual edition of the PowerShell+DevOps Global Summit. We lost our 2020 event to the pandemic but fortunately, the people at The DevOps Collective were able to pull together a fantastic virtual event. There were as many virtual attendees as we normally have at the\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/04\/get-pscountdown-format2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/04\/get-pscountdown-format2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/04\/get-pscountdown-format2.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/04\/get-pscountdown-format2.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1900,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1900\/friday-fun-is-it-today\/","url_meta":{"origin":2951,"position":4},"title":"Friday Fun Is It Today?","author":"Jeffery Hicks","date":"December 16, 2011","format":false,"excerpt":"I was testing out the PowerShell cmdlets that ship with Backup and Replication from Veeam Software. I was using the cmdlet to return backup jobs and realized I needed a way to only get those objects where the date was today. Because the property was a complete date time object,\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":5850,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5850\/extending-powershell-datetime-objects\/","url_meta":{"origin":2951,"position":5},"title":"Extending PowerShell DateTime Objects","author":"Jeffery Hicks","date":"December 28, 2017","format":false,"excerpt":"I've been experimenting more with my PSTypeExtensionTools module, finding more objects to enhance.\u00a0 You can check out the project on Github and install the module from the PowerShell Gallery. My current fun has been with the DateTime object \u2013 specifically converting a value into another culture.\u00a0 Apparently those of us\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-13.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-13.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/12\/image_thumb-13.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2951"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2951\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}