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
Comments
- Anonymous
February 06, 2006
I'd say you ran it far too early this morning (5:51:34)? - Anonymous
February 06, 2006
We've got a winner! Here is the solution.
MSH> [datetime]"12/25/2006" - [timespan]277997061718750
Monday, February 06, 2006 5:51:33 AM
The punchline is that there are a lot of .NET types which save you a ton pain and bugs by doing their own string parsing. Leverage this whenever you can.
Jeffrey P. Snover [MSFT] - Anonymous
February 06, 2006
Amen to that. Did somebody say System.Uri? - Anonymous
February 06, 2006
an other way :
([dateTime]"12/25/2006").addticks(-277997061718750)
I did this for newyear with a big clock :
http://mow001.blogspot.com/2005/12/monad-newyears-clock.html
and for the Daylight Time change :
http://mow001.blogspot.com/2005/10/when-to-change-your-clock-ask-monad.html
gr //o// - Anonymous
February 08, 2006
hello,jeffery:
I have a question to distruble you:
where can I find more ".NET types"?I mean is there a list of ".NET type" available in monad?
thanks for your reply.
applepwc - Anonymous
February 08, 2006
I'm very sorry for my inattention.
"jeffery" should be "jeffrey"