I have been playing a bit with dates and times in Monad. In Monad, you can create a variable as a date-time object, using .NET's build in datetime class, as follows:
$[C:\]> [datetime] $xmas = "12.25.2005"
You can use this, either to assign a value or in a calculation, such as: :
$[C:\]> $xmas - [datetime]::now
Days : 159
Hours : 8
Minutes : 28
Seconds : 38
Milliseconds : 558
Ticks : 137681185582531
TotalDays : 159.353224053855
TotalHours : 3824.47737729253
TotalMinutes : 229468.642637552
TotalSeconds : 13768118.5582531
TotalMilliseconds : 13768118558.2531
At TechEd, Jeffrey Snover said his daugher was really excited about how long it is till Christmas. Just for her, here's how to jazz it up a bit and create a simple function to calculate the days till Christmas:
function cdtx {[datetime]$x= "12.25.2005"; return $x-[datetime]::now}
Jeffrey could put this function definintion into his profile.msh to have it at his fingertips should it be needed (ie when his daugter asks him again). But for even more fun, why not get monad to just tell her how many days it is, Using the say-text cmdlet I posted about earlier:
say-text "It is $($xmas-[datetime]::now).days until till christmas"
It's a little pedantic - and rather precise - but it's fun.
No comments:
Post a Comment