Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Time span Help

Reply
 
Old 02-23-2007   #1 (permalink)
Techstarts
Guest


 
 

Time span Help

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



My System SpecsSystem Spec
Old 02-23-2007   #2 (permalink)
mikes.net
Guest


 
 

Re: Time span Help

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



My System SpecsSystem Spec
Old 02-23-2007   #3 (permalink)
RichS
Guest


 
 

Re: Time span Help

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

>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Horizontal Span Dual Monitor Vista Games
Bring Horizontal Span back please! Vista General
Horizontal Span Vista General
Horizontal Span Vista General
Screen Saver Won't Span Dual Monitors Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46