I put the statements into a script as follows
New-TimeSpan (get-date -day 02 -month 06 -year 2005)
$M=get-date -Year 2005 -Month 06 -Day 02
$t=get-date
$t.subtract($m)
and got the following results
PS> ./testdates.ps1
Days : 631
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 0
Ticks : 545184000000000
TotalDays : 631
TotalHours : 15144
TotalMinutes : 908640
TotalSeconds : 54518400
TotalMilliseconds : 54518400000
Days : 631
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 0
Ticks : 545184000000000
TotalDays : 631
TotalHours : 15144
TotalMinutes : 908640
TotalSeconds : 54518400
TotalMilliseconds : 54518400000
which are the same as far as I can see.
How much time was there between the issuing of the commands at the prompt?
Remember that get-date gets the time as well as the date
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog:
http://richardsiddaway.spaces.live.com/
PowerShell User Group:
http://www.get-psuguk.org.uk
"mikes.net" wrote:
> Because in the second example you did not and could not issue the two
> date commands intantaneously. Notice that the number of days is
> almost 631:
>
> TotalDays : 630.996613136574.
>
> Perhaps the following will help you to see this better:
>
> PS > $tomorrow =(get-date).adddays(1)
> PS > $today = get-date
> PS > $tomorrow - $today
>
> Days : 0
> Hours : 23
> Minutes : 59
> Seconds : 54
> Milliseconds : 500
> Ticks : 863945000000
> TotalDays : 0.999936342592593
> TotalHours : 23.9984722222222
> TotalMinutes : 1439.90833333333
> TotalSeconds : 86394.5
> TotalMilliseconds : 86394500
>
> Did I misunderstand the question?
>
> Mike
>
>
>
> On Feb 23, 5:05 am, "Techstarts" <preetamz...@gmail.com> wrote:
> > I'm trying to find the amount of time between spend between june 02 till date. I'm getting different results if I use timespan and when I use Subtract method.
> >
> > Comment would clarify concept behind it.
> >
> > PS E:\cmdlets> New-TimeSpan (get-date -day 02 -month 06 -year 2005)
> >
> > Days : 631
> > Hours : 0
> > Minutes : 0
> > Seconds : 0
> > Milliseconds : 0
> > Ticks : 545184000000000
> > TotalDays : 631
> > TotalHours : 15144
> > TotalMinutes : 908640
> > TotalSeconds : 54518400
> > TotalMilliseconds : 54518400000
> > --------------------------------------------------------------------------------
> > $M=get-date -Year 2005 -Month 06 -Day 02
> > $T=get-date
> > $T.subtract($M)
> >
> > PS E:\cmdlets> $T.Subtract($M)
> >
> > Days : 630
> > Hours : 23
> > Minutes : 55
> > Seconds : 7
> > Milliseconds : 375
> > Ticks : 545181073750000
> > TotalDays : 630.996613136574
> > TotalHours : 15143.9187152778
> > TotalMinutes : 908635.122916667
> > TotalSeconds : 54518107.375
> > TotalMilliseconds : 54518107375
>
>
>