{"id":10571,"date":"2006-04-25T12:18:21","date_gmt":"2006-04-25T12:18:21","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/04\/25\/days-till-xmas\/"},"modified":"2019-02-18T13:24:55","modified_gmt":"2019-02-18T20:24:55","slug":"days-till-xmas","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/days-till-xmas\/","title":{"rendered":"Days till Xmas"},"content":{"rendered":"<p>My daughter loves christmas.&nbsp; She often asks me, &#8220;how long is it till christmas?&#8221;&nbsp; The problem with that is that I&#8217;m one of those people that can barely remember what year it is much less the date.&nbsp; Well, it is one thing to be a flawed person and its another thing to disappoint your daughter.&nbsp; Monad to the rescue!<\/p>\n<p>Here is a little date math routine I wrote to help me out:<\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\">function tillXmas ()<br \/>{<br \/>&nbsp;&nbsp;&nbsp; $now = [DateTime]::Now<br \/>&nbsp;&nbsp;&nbsp; [Datetime](&#8220;12\/25\/&#8221; + $now.Year) &#8211; $Now<br \/>}<\/font><\/p>\n<p><font face=\"Courier New\" color=\"#ff0000\">MSH&gt; tillxmas<\/font><\/p>\n<p><font color=\"#ff0000\"><br \/><font face=\"Courier New\">Days&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 321<br \/>Hours&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 18<br \/>Minutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 8<br \/>Seconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 26<br \/>Milliseconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 171<br \/>Ticks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 277997061718750<br \/>TotalDays&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 321.755858470775<br \/>TotalHours&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7722.14060329861<br \/>TotalMinutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 463328.436197917<br \/>TotalSeconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 27799706.171875<br \/>TotalMilliseconds : 27799706171.875<\/font><\/font><\/p>\n<p>Thanks to Monad, I can tell my daughter how many seconds to go till Xmas!&nbsp; Now if I can only get her to stop asking me in the car.<\/p>\n<p>Here is an exercise for you &#8211; calculate what time I ran this example (hint &#8211; think &#8220;date math&#8221; and use the Ticks value)<\/p>\n<p>Enjoy!<\/p>\n<p>Jeffrey P. Snover<br \/>Monad Architect<\/p>\n<p>[<i>Edit: Monad has now been renamed to Windows PowerShell.  This script or discussion may require slight adjustments before it applies directly to newer builds.<\/i>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My daughter loves christmas.&nbsp; She often asks me, &#8220;how long is it till christmas?&#8221;&nbsp; The problem with that is that I&#8217;m one of those people that can barely remember what year it is much less the date.&nbsp; Well, it is one thing to be a flawed person and its another thing to disappoint your daughter.&nbsp; [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10571","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>My daughter loves christmas.&nbsp; She often asks me, &#8220;how long is it till christmas?&#8221;&nbsp; The problem with that is that I&#8217;m one of those people that can barely remember what year it is much less the date.&nbsp; Well, it is one thing to be a flawed person and its another thing to disappoint your daughter.&nbsp; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=10571"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10571\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=10571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}