Welcome to MSDN Blogs Sign in | Join | Help

Days till Xmas

My daughter loves christmas.  She often asks me, "how long is it till christmas?"  The problem with that is that I'm one of those people that can barely remember what year it is much less the date.  Well, it is one thing to be a flawed person and its another thing to disappoint your daughter.  Monad to the rescue!

Here is a little date math routine I wrote to help me out:

function tillXmas ()
{
    $now = [DateTime]::Now
    [Datetime]("12/25/" + $now.Year) - $Now
}

MSH> tillxmas


Days              : 321
Hours             : 18
Minutes           : 8
Seconds           : 26
Milliseconds      : 171
Ticks             : 277997061718750
TotalDays         : 321.755858470775
TotalHours        : 7722.14060329861
TotalMinutes      : 463328.436197917
TotalSeconds      : 27799706.171875
TotalMilliseconds : 27799706171.875

Thanks to Monad, I can tell my daughter how many seconds to go till Xmas!  Now if I can only get her to stop asking me in the car.

Here is an exercise for you - calculate what time I ran this example (hint - think "date math" and use the Ticks value)

Enjoy!

Jeffrey P. Snover
Monad Architect

[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]

Published Tuesday, April 25, 2006 5:18 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Days till Xmas

thers 34 days till xmas yyyyyyeeeeeaaaaaaaa

Wednesday, November 21, 2007 5:38 PM by 643532

# Xmas PowerGUI Wallpaper « Dmitry’s PowerBlog: PowerShell and beyond

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker