New-TimeSpan

 

Additional Resources for New-TimeSpan

 

Performing Date Arithmetic

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/new-timespan.mspx

 

 

SYNOPSIS

Creates a TimeSpan object.

 

SYNTAX

New-TimeSpan [[-start] <DateTime>] [[-end] <DateTime>] [<CommonParameters>]

New-TimeSpan [-days <int>] [-hours <int>] [-minutes <int>] [-seconds <int>] [<CommonParameters>]

 

DETAILED DESCRIPTION

Creates a TimeSpan object. The resulting object can be used to add or subtract time from a DateTime object to create additional DateTime objects.

 

PARAMETERS

 

-start <DateTime>

Indicates the start of a timespan.

 

Required?

false

Position?

1

Default value

 

Accept pipeline input?  

true (ByValue, ByPropertyName)

Accept wildcard characters? 

false

 

-end <DateTime>

Indicates the end of a timespan.

 

Required?

false

Position?

2

Default value

Now

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

-days <int>

Indicates the days in the timespan.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-hours <int>

Indicates the hours in the timespan.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-minutes <int>

Indicates the minutes in the timespan.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-seconds <int>

Indicates the seconds in the timespan.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

None

 

RETURN TYPE

TimeSpanObject

 

NOTES

 

For more information, type "Get-Help New-TimeSpan  -detailed". For technical information, type "Get-Help New-TimeSpan -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

$timespan = new-timespan -hour 1 -minute 25

 

This command creates a TimeSpan object of duration 1 hour and 25 minutes and stores it in a variable named $timespan. It displays a representation of the TimeSpan object.

 

EXAMPLE 2

 

$timespan = new-timespan (get-date -year 1970 -month 02 -day 26)

 

This example creates a new TimeSpan object that represents the duration between when the command is run and February 26, 1970.

 

RELATED LINKS

Set-Date

Get-Date