Quality Assurance: February 2012 Archives

Powershell makes doing math on Date object easier than falling down!

 

   1: $time = Get-Date;
   2: 
   3: ##Show Minutes
   4: $time.Minutes;
   5: 
   6: ##Show Day
   7: $time.Day;
   8: 
   9: ##Find out NOW stuff
  10: (Get-Date).Day;
  11: (Get-Date).Millisecond;
  12:  
  13: ##What Will the Date be 90 days from now?
  14: (Get-Date).AddDays(90);
  15: 
  16: ##What was the day 90 days ago?
  17: (Get-Date).AddDays(-90);
  18: 
  19: ## And for something practical
  20: $startTime = Get-Date;
  21: $endTime = Get-Date;
  22: "DONE in less than " + ($endTime.AddMinutes(1) - $startTime).Minutes + " Minutes";

 

As you can see, wonderfully simple.

Technorati Tags: ,,,,,,,,,
Windows Live Tags: PowerShell,Date,Math,Minutes,Find,Millisecond,AddDays,AddMinutes,startTime,endTime

 

 

The Tao of Calvin