That's what I thought to but as soon as you apply formatting the object seems 
to get converted to a string and you can no longer perform calculations. Also 
turns out New-TimeSpan has no built-in formatting capability.

Mitch provided the simple solution of just using .net methods which work treat. 
:)

i.e. $duration = $end.Subtract($start)

Regards,

Paul

--
Online Developer/SharePoint Administrator,
ICT Infrastructure Team
CEO Sydney

From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Prashanth Thiyagalingam
Sent: Thursday, 12 January 2012 3:17 PM
To: ozmoss@ozmoss.com
Subject: RE: PowerShell date calculations

you could use
Get-Date -Format "hh:mm:ss"


________________________________
From: paul.no...@ceosyd.catholic.edu.au
To: ozmoss@ozmoss.com
Date: Thu, 12 Jan 2012 13:10:05 +1100
Subject: PowerShell date calculations
I've managed to produce what I want below but have first had to convert the 
Get-Date objects to datetime. Is there a more straightforward way? I tried the 
New-TimeSpan cmdlet but couldn't see a way to just extract what I needed 
-TotalSeconds - and then reformat it.
# Backup the site and calculate time taken
$start = Get-Date
$startNow = [system.datetime]$start
$startTime = $start.ToString('hh:mm:ss')

Backup-SPSite -Identity $site.Url -Path $backupPath

$end = Get-Date
$endNow = [system.datetime]$end
$endTime = $start.ToString('hh:mm:ss')

$duration = ($endNow - $startNow)

Start

12:56:26

$startTime

End

12:56:27

$endTime

Duration

00:00:00.5937538

$duration


Kind regards,

Paul Noone

---------------------------------------------------
Online Developer/SharePoint Administrator
Infrastructure Team, ICT
Catholic Education Office, Sydney
p: (02) 9568 8461
f: (02) 9568 8483
e: paul.no...@ceosyd.catholic.edu.au<mailto:paul.no...@ceosyd.catholic.edu.au>
w: http://www.ceosyd.catholic.edu.au/


_______________________________________________ ozmoss mailing list 
ozmoss@ozmoss.com<mailto:ozmoss@ozmoss.com> 
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss
_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to