From 4f7d3afe7a976df83f2212d9c5415ee5a79dcefd Mon Sep 17 00:00:00 2001 From: Bobby Reed Date: Wed, 1 May 2019 06:38:54 -0400 Subject: [PATCH] Updating New-TimeSpan --- .../New-TimeSpan.md | 112 +++++++++------ .../New-TimeSpan.md | 132 +++++++++++------- .../New-TimeSpan.md | 93 +++++++----- .../New-TimeSpan.md | 110 ++++++++++----- .../New-TimeSpan.md | 112 ++++++++++----- 5 files changed, 362 insertions(+), 197 deletions(-) diff --git a/reference/3.0/Microsoft.PowerShell.Utility/New-TimeSpan.md b/reference/3.0/Microsoft.PowerShell.Utility/New-TimeSpan.md index 68efd6375bc0..c387ea6d2f70 100644 --- a/reference/3.0/Microsoft.PowerShell.Utility/New-TimeSpan.md +++ b/reference/3.0/Microsoft.PowerShell.Utility/New-TimeSpan.md @@ -1,5 +1,5 @@ --- -ms.date: 06/09/2017 +ms.date: 5/1/2019 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet @@ -10,7 +10,6 @@ title: New-TimeSpan # New-TimeSpan ## SYNOPSIS - Creates a TimeSpan object. ## SYNTAX @@ -29,45 +28,75 @@ New-TimeSpan [-Days ] [-Hours ] [-Minutes ] [-Seconds Get-ChildItem $pshome\en-us\about_remote.help.txt | new-timespan +```Output Days : 321 Hours : 21 Minutes : 59 @@ -79,24 +108,14 @@ TotalHours : 7725.98953132578 TotalMinutes : 463559.371879547 TotalSeconds : 27813562.3127728 TotalMilliseconds : 27813562312.7728 - -# Equivalent to: - -PS> new-timespan -start (Get-ChildItem $pshome\en-us\about_remote.help.txt).lastwritetime ``` -This command tells you how long it has been since the about_remote.help.txt file was last updated. -You can use this command format on any file, and on any other object that has a LastWriteTime property. - -This command works because the Start parameter of New-TimeSpan has an alias of LastWriteTime. -When you pipe an object that has a LastWriteTime property to New-TimeSpan, Windows PowerShell uses the value of the LastWriteTime property as the value of the Start parameter. - ## PARAMETERS ### -Days -Indicates the days in the time span. -The default is 0. +Specifies the days in the time span. +The default value is 0. ```yaml Type: Int32 @@ -112,8 +131,8 @@ Accept wildcard characters: False ### -End -Indicates the end of a time span. -The default is the current date and time. +Specifies the end of a time span. +The default value is the current date and time. ```yaml Type: DateTime @@ -129,8 +148,8 @@ Accept wildcard characters: False ### -Hours -Indicates the hours in the time span. -The default is zero. +Specifies the hours in the time span. +The default value is zero. ```yaml Type: Int32 @@ -146,8 +165,8 @@ Accept wildcard characters: False ### -Minutes -Indicates the minutes in the time span. -The default is 0. +Specifies the minutes in the time span. +The default value is 0. ```yaml Type: Int32 @@ -163,8 +182,8 @@ Accept wildcard characters: False ### -Seconds -Indicates the length of the time span in seconds. -The default is 0. +Specifies the length of the time span in seconds. +The default value is 0. ```yaml Type: Int32 @@ -180,12 +199,13 @@ Accept wildcard characters: False ### -Start -Indicates the start of a time span. -Enter a string that represents the date and time, such as "3/15/09" or a DateTime object, such as one from a Get-Date command. -The default is the current date and time. +Specifies the start of a time span. +Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such +as one from a `Get-Date` command. The default value is the current date and time. -You can use Start or its alias, LastWriteTime. -The LastWriteTime alias lets you pipe objects that have a LastWriteTime property, such as files in the file system (System.Io.FileIO), to the Start parameter of New-TimeSpan. +You can use **Start** or its alias, **LastWriteTime**. +The **LastWriteTime** alias lets you pipe objects that have a **LastWriteTime** property, +such as files in the file system `[System.Io.FileIO]`, to the **Start** parameter of `New-TimeSpan`. ```yaml Type: DateTime @@ -201,19 +221,21 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, +-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, +-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md). ## INPUTS ### System.DateTime -You can pipe a DateTime object that represents that start time to New-TimeSpan. +You can pipe a **DateTime** object that represents that start time to `New-TimeSpan`. ## OUTPUTS ### System.TimeSpan -New-TimeSpan returns an object that represents the time span. +`New-TimeSpan` returns an object that represents the time span. ## NOTES diff --git a/reference/4.0/Microsoft.PowerShell.Utility/New-TimeSpan.md b/reference/4.0/Microsoft.PowerShell.Utility/New-TimeSpan.md index 1f7ac8843db1..4ac908295b01 100644 --- a/reference/4.0/Microsoft.PowerShell.Utility/New-TimeSpan.md +++ b/reference/4.0/Microsoft.PowerShell.Utility/New-TimeSpan.md @@ -1,5 +1,5 @@ --- -ms.date: 06/09/2017 +ms.date: 5/1/2019 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet @@ -7,7 +7,6 @@ online version: http://go.microsoft.com/fwlink/p/?linkid=293994 external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml title: New-TimeSpan --- - # New-TimeSpan ## SYNOPSIS @@ -16,51 +15,88 @@ Creates a TimeSpan object. ## SYNTAX ### Date (Default) + ``` New-TimeSpan [[-Start] ] [[-End] ] [] ``` ### Time + ``` New-TimeSpan [-Days ] [-Hours ] [-Minutes ] [-Seconds ] [] ``` ## DESCRIPTION -The New-TimeSpan cmdlet creates a TimeSpan object that represents a time interval You can use a TimeSpan object to add or subtract time from DateTime objects. -Without parameters, a "New-Timespan" command returns a timespan object that represents a time interval of zero. +The `New-TimeSpan` cmdlet creates a **TimeSpan** object that represents a time interval. +You can use a **TimeSpan** object to add or subtract time from **DateTime** objects. + +Without parameters, a `New-TimeSpan` command returns a **TimeSpan** object that represents a time +interval of zero. ## EXAMPLES -### Example 1 -``` -PS C:\> $timespan = new-timespan -hour 1 -minute 25 -``` +### Example 1: Create a TimeSpan object for a specified duration -This command creates a TimeSpan object with a duration of 1 hour and 25 minutes and stores it in a variable named $timespan. -It displays a representation of the TimeSpan object. +This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in +a variable named `$TimeSpan`. It displays a representation of the **TimeSpan** object. -### Example 2 +```powershell +$TimeSpan = New-TimeSpan -Hours 1 -Minutes 25 +$TimeSpan ``` -PS C:\> new-timespan -end (get-date -year 2010 -month 1 -day 1) + +```Output +Days : 0 +Hours : 1 +Minutes : 25 +Seconds : 0 +Milliseconds : 0 +Ticks : 51000000000 +TotalDays : 0.0590277777777778 +TotalHours : 1.41666666666667 +TotalMinutes : 85 +TotalSeconds : 5100 +TotalMilliseconds : 5100000 ``` -This example creates a new TimeSpan object that represents the interval between the time that the command is run and January 1, 2010. +### Example 2: Create a TimeSpan object for a time interval -This command does not require the Start parameter, because the default value of the Start parameter is the current date and time. +This example creates a new **TimeSpan** object that represents the interval between the time that +the command is run and January 1, 2010. -### Example 3 +This command does not require the **Start** parameter, because the default value of the **Start** +parameter is the current date and time. + +```powershell +New-TimeSpan -End (Get-Date -Year 2010 -Month 1 -Day 1) ``` -PS C:\> $90days = new-timespan -days 90 -PS C:\> (get-date) + $90days + +### Example 3: Get the date 90 days from the current date + +```powershell +$90days = New-TimeSpan -Days 90 +(Get-Date) + $90days ``` These commands return the date that is 90 days after the current date. -### Example 4 +### Example 4: Discover the TimeSpan since a file was updated + +This command tells you how long it has been since the [about_remote](../Microsoft.PowerShell.Core/About/about_Remote.md) +help file was last updated. +You can use this command format on any file, or any other object that has a **LastWriteTime** +property. + +This command works because the **Start** parameter of `New-TimeSpan` has an alias of +**LastWriteTime**. When you pipe an object that has a **LastWriteTime** property to `New-TimeSpan`, +PowerShell uses the value of the **LastWriteTime** property as the value of the **Start** parameter. + +```powershell +Get-ChildItem $PSHOME\en-us\about_remote.help.txt | New-TimeSpan ``` -PS C:\> dir $pshome\en-us\about_remote.help.txt | new-timespan +```Output Days : 321 Hours : 21 Minutes : 59 @@ -72,23 +108,14 @@ TotalHours : 7725.98953132578 TotalMinutes : 463559.371879547 TotalSeconds : 27813562.3127728 TotalMilliseconds : 27813562312.7728 - -# Equivalent to: - -PS C:\> new-timespan -start (dir $pshome\en-us\about_remote.help.txt).lastwritetime ``` -This command tells you how long it has been since the about_remote.help.txt file was last updated. -You can use this command format on any file, and on any other object that has a LastWriteTime property. - -This command works because the Start parameter of New-TimeSpan has an alias of LastWriteTime. -When you pipe an object that has a LastWriteTime property to New-TimeSpan, Windows PowerShell uses the value of the LastWriteTime property as the value of the Start parameter. - ## PARAMETERS ### -Days -Indicates the days in the time span. -The default is 0. + +Specifies the days in the time span. +The default value is 0. ```yaml Type: Int32 @@ -103,8 +130,9 @@ Accept wildcard characters: False ``` ### -End -Indicates the end of a time span. -The default is the current date and time. + +Specifies the end of a time span. +The default value is the current date and time. ```yaml Type: DateTime @@ -119,8 +147,9 @@ Accept wildcard characters: False ``` ### -Hours -Indicates the hours in the time span. -The default is zero. + +Specifies the hours in the time span. +The default value is zero. ```yaml Type: Int32 @@ -135,8 +164,9 @@ Accept wildcard characters: False ``` ### -Minutes -Indicates the minutes in the time span. -The default is 0. + +Specifies the minutes in the time span. +The default value is 0. ```yaml Type: Int32 @@ -151,8 +181,9 @@ Accept wildcard characters: False ``` ### -Seconds -Indicates the length of the time span in seconds. -The default is 0. + +Specifies the length of the time span in seconds. +The default value is 0. ```yaml Type: Int32 @@ -167,12 +198,14 @@ Accept wildcard characters: False ``` ### -Start -Indicates the start of a time span. -Enter a string that represents the date and time, such as "3/15/09" or a DateTime object, such as one from a Get-Date command. -The default is the current date and time. -You can use Start or its alias, LastWriteTime. -The LastWriteTime alias lets you pipe objects that have a LastWriteTime property, such as files in the file system (System.Io.FileIO), to the Start parameter of New-TimeSpan. +Specifies the start of a time span. +Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such +as one from a `Get-Date` command. The default value is the current date and time. + +You can use **Start** or its alias, **LastWriteTime**. +The **LastWriteTime** alias lets you pipe objects that have a **LastWriteTime** property, +such as files in the file system `[System.Io.FileIO]`, to the **Start** parameter of `New-TimeSpan`. ```yaml Type: DateTime @@ -187,17 +220,22 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, +-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, +-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md). ## INPUTS ### System.DateTime -You can pipe a DateTime object that represents that start time to New-TimeSpan. + +You can pipe a **DateTime** object that represents that start time to `New-TimeSpan`. ## OUTPUTS ### System.TimeSpan -New-TimeSpan returns an object that represents the time span. + +`New-TimeSpan` returns an object that represents the time span. ## NOTES diff --git a/reference/5.0/Microsoft.PowerShell.Utility/New-TimeSpan.md b/reference/5.0/Microsoft.PowerShell.Utility/New-TimeSpan.md index 769bca436123..bde4662b3fa9 100644 --- a/reference/5.0/Microsoft.PowerShell.Utility/New-TimeSpan.md +++ b/reference/5.0/Microsoft.PowerShell.Utility/New-TimeSpan.md @@ -1,5 +1,5 @@ --- -ms.date: 06/09/2017 +ms.date: 5/1/2019 schema: 2.0.0 locale: en-us keywords: powershell,cmdlet @@ -28,45 +28,75 @@ New-TimeSpan [-Days ] [-Hours ] [-Minutes ] [-Seconds $TimeSpan = New-TimeSpan -Hour 1 -Minute 25 +This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in +a variable named `$TimeSpan`. It displays a representation of the **TimeSpan** object. + +```powershell +$TimeSpan = New-TimeSpan -Hours 1 -Minutes 25 +$TimeSpan ``` -This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in a variable named $TimeSpan. -It displays a representation of the **TimeSpan** object. +```Output +Days : 0 +Hours : 1 +Minutes : 25 +Seconds : 0 +Milliseconds : 0 +Ticks : 51000000000 +TotalDays : 0.0590277777777778 +TotalHours : 1.41666666666667 +TotalMinutes : 85 +TotalSeconds : 5100 +TotalMilliseconds : 5100000 +``` ### Example 2: Create a TimeSpan object for a time interval -``` -PS C:\> new-timespan -end (get-date -year 2010 -month 1 -day 1) -``` +This example creates a new **TimeSpan** object that represents the interval between the time that +the command is run and January 1, 2010. -This example creates a new **TimeSpan** object that represents the interval between the time that the command is run and January 1, 2010. +This command does not require the **Start** parameter, because the default value of the **Start** +parameter is the current date and time. -This command does not require the *Start* parameter, because the default value of the *Start* parameter is the current date and time. +```powershell +New-TimeSpan -End (Get-Date -Year 2010 -Month 1 -Day 1) +``` ### Example 3: Get the date 90 days from the current date -``` -PS C:\> $90days = New-TimeSpan -Days 90 -PS C:\> (Get-Date) + $90days +```powershell +$90days = New-TimeSpan -Days 90 +(Get-Date) + $90days ``` These commands return the date that is 90 days after the current date. ### Example 4: Discover the TimeSpan since a file was updated +This command tells you how long it has been since the [about_remote](../Microsoft.PowerShell.Core/About/about_Remote.md) +help file was last updated. +You can use this command format on any file, or any other object that has a **LastWriteTime** +property. + +This command works because the **Start** parameter of `New-TimeSpan` has an alias of +**LastWriteTime**. When you pipe an object that has a **LastWriteTime** property to `New-TimeSpan`, +PowerShell uses the value of the **LastWriteTime** property as the value of the **Start** parameter. + +```powershell +Get-ChildItem $PSHOME\en-us\about_remote.help.txt | New-TimeSpan ``` -PS C:\> dir $pshome\en-us\about_remote.help.txt | New-TimeSpan + +```Output Days : 321 Hours : 21 Minutes : 59 @@ -77,17 +107,9 @@ TotalDays : 321.916230471907 TotalHours : 7725.98953132578 TotalMinutes : 463559.371879547 TotalSeconds : 27813562.3127728 -TotalMilliseconds : 27813562312.7728 PS C:\> # Equivalent to: - -PS C:\> New-TimeSpan -Start (dir $pshome\en-us\about_remote.help.txt).lastwritetime +TotalMilliseconds : 27813562312.7728 ``` -This command tells you how long it has been since the about_remote.help.txt file was last updated. -You can use this command format on any file, and on any other object that has a **LastWriteTime** property. - -This command works because the *Start* parameter of **New-TimeSpan** has an alias of LastWriteTime. -When you pipe an object that has a Last****WriteTime property to **New-TimeSpan**, Windows PowerShell uses the value of the **LastWriteTime** property as the value of the *Start* parameter. - ## PARAMETERS ### -Days @@ -119,7 +141,7 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: Current date and time Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` @@ -178,11 +200,12 @@ Accept wildcard characters: False ### -Start Specifies the start of a time span. -Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such as one from a Get-Date command. -The default value is the current date and time. +Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such +as one from a `Get-Date` command. The default value is the current date and time. -You can use *Start* or its alias, LastWriteTime. -The LastWriteTime alias lets you pipe objects that have a **LastWriteTime** property, such as files in the file system (System.Io.FileIO), to the Start parameter of **New-TimeSpan**. +You can use **Start** or its alias, **LastWriteTime**. +The **LastWriteTime** alias lets you pipe objects that have a **LastWriteTime** property, +such as files in the file system `[System.Io.FileIO]`, to the **Start** parameter of `New-TimeSpan`. ```yaml Type: DateTime @@ -191,26 +214,28 @@ Aliases: LastWriteTime Required: False Position: 0 -Default value: None +Default value: Current date and time Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, +-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, +-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md). ## INPUTS ### System.DateTime -You can pipe a **DateTime** object that represents that start time to **New-TimeSpan**. +You can pipe a **DateTime** object that represents that start time to `New-TimeSpan`. ## OUTPUTS ### System.TimeSpan -**New-TimeSpan** returns an object that represents the time span. +`New-TimeSpan` returns an object that represents the time span. ## NOTES diff --git a/reference/5.1/Microsoft.PowerShell.Utility/New-TimeSpan.md b/reference/5.1/Microsoft.PowerShell.Utility/New-TimeSpan.md index a383e4ba601d..b3b6b88053f1 100644 --- a/reference/5.1/Microsoft.PowerShell.Utility/New-TimeSpan.md +++ b/reference/5.1/Microsoft.PowerShell.Utility/New-TimeSpan.md @@ -3,12 +3,11 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml keywords: powershell,cmdlet locale: en-us Module Name: Microsoft.PowerShell.Utility -ms.date: 06/09/2017 +ms.date: 5/1/2019 online version: http://go.microsoft.com/fwlink/?LinkId=821837 schema: 2.0.0 title: New-TimeSpan --- - # New-TimeSpan ## SYNOPSIS @@ -17,51 +16,88 @@ Creates a TimeSpan object. ## SYNTAX ### Date (Default) + ``` New-TimeSpan [[-Start] ] [[-End] ] [] ``` ### Time + ``` New-TimeSpan [-Days ] [-Hours ] [-Minutes ] [-Seconds ] [] ``` ## DESCRIPTION -The **New-TimeSpan** cmdlet creates a **TimeSpan** object that represents a time interval. + +The `New-TimeSpan` cmdlet creates a **TimeSpan** object that represents a time interval. You can use a **TimeSpan** object to add or subtract time from **DateTime** objects. -Without parameters, a **New-Timespan** command returns a timespan object that represents a time interval of zero. +Without parameters, a `New-TimeSpan` command returns a **TimeSpan** object that represents a time +interval of zero. ## EXAMPLES ### Example 1: Create a TimeSpan object for a specified duration -``` -PS C:\> $TimeSpan = New-TimeSpan -Hour 1 -Minute 25 -``` -This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in a variable named $TimeSpan. -It displays a representation of the **TimeSpan** object. +This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in +a variable named `$TimeSpan`. It displays a representation of the **TimeSpan** object. -### Example 2: Create a TimeSpan object for a time interval +```powershell +$TimeSpan = New-TimeSpan -Hours 1 -Minutes 25 +$TimeSpan ``` -PS C:\> new-timespan -end (get-date -year 2010 -month 1 -day 1) + +```Output +Days : 0 +Hours : 1 +Minutes : 25 +Seconds : 0 +Milliseconds : 0 +Ticks : 51000000000 +TotalDays : 0.0590277777777778 +TotalHours : 1.41666666666667 +TotalMinutes : 85 +TotalSeconds : 5100 +TotalMilliseconds : 5100000 ``` -This example creates a new **TimeSpan** object that represents the interval between the time that the command is run and January 1, 2010. +### Example 2: Create a TimeSpan object for a time interval -This command does not require the *Start* parameter, because the default value of the *Start* parameter is the current date and time. +This example creates a new **TimeSpan** object that represents the interval between the time that +the command is run and January 1, 2010. -### Example 3: Get the date 90 days from the current date +This command does not require the **Start** parameter, because the default value of the **Start** +parameter is the current date and time. + +```powershell +New-TimeSpan -End (Get-Date -Year 2010 -Month 1 -Day 1) ``` -PS C:\> $90days = New-TimeSpan -Days 90 -PS C:\> (Get-Date) + $90days + +### Example 3: Get the date 90 days from the current date + +```powershell +$90days = New-TimeSpan -Days 90 +(Get-Date) + $90days ``` These commands return the date that is 90 days after the current date. ### Example 4: Discover the TimeSpan since a file was updated + +This command tells you how long it has been since the [about_remote](../Microsoft.PowerShell.Core/About/about_Remote.md) +help file was last updated. +You can use this command format on any file, or any other object that has a **LastWriteTime** +property. + +This command works because the **Start** parameter of `New-TimeSpan` has an alias of +**LastWriteTime**. When you pipe an object that has a **LastWriteTime** property to `New-TimeSpan`, +PowerShell uses the value of the **LastWriteTime** property as the value of the **Start** parameter. + +```powershell +Get-ChildItem $PSHOME\en-us\about_remote.help.txt | New-TimeSpan ``` -PS C:\> dir $pshome\en-us\about_remote.help.txt | New-TimeSpan + +```Output Days : 321 Hours : 21 Minutes : 59 @@ -72,20 +108,13 @@ TotalDays : 321.916230471907 TotalHours : 7725.98953132578 TotalMinutes : 463559.371879547 TotalSeconds : 27813562.3127728 -TotalMilliseconds : 27813562312.7728 PS C:\> # Equivalent to: - -PS C:\> New-TimeSpan -Start (dir $pshome\en-us\about_remote.help.txt).lastwritetime +TotalMilliseconds : 27813562312.7728 ``` -This command tells you how long it has been since the about_remote.help.txt file was last updated. -You can use this command format on any file, and on any other object that has a **LastWriteTime** property. - -This command works because the *Start* parameter of **New-TimeSpan** has an alias of LastWriteTime. -When you pipe an object that has a **LastWriteTime** property to **New-TimeSpan**, Windows PowerShell uses the value of the **LastWriteTime** property as the value of the *Start* parameter. - ## PARAMETERS ### -Days + Specifies the days in the time span. The default value is 0. @@ -102,6 +131,7 @@ Accept wildcard characters: False ``` ### -End + Specifies the end of a time span. The default value is the current date and time. @@ -112,12 +142,13 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: Current date and time Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` ### -Hours + Specifies the hours in the time span. The default value is zero. @@ -134,6 +165,7 @@ Accept wildcard characters: False ``` ### -Minutes + Specifies the minutes in the time span. The default value is 0. @@ -150,6 +182,7 @@ Accept wildcard characters: False ``` ### -Seconds + Specifies the length of the time span in seconds. The default value is 0. @@ -166,12 +199,14 @@ Accept wildcard characters: False ``` ### -Start + Specifies the start of a time span. -Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such as one from a Get-Date command. -The default value is the current date and time. +Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such +as one from a `Get-Date` command. The default value is the current date and time. -You can use *Start* or its alias, LastWriteTime. -The LastWriteTime alias lets you pipe objects that have a **LastWriteTime** property, such as files in the file system (System.Io.FileIO), to the Start parameter of **New-TimeSpan**. +You can use **Start** or its alias, **LastWriteTime**. +The **LastWriteTime** alias lets you pipe objects that have a **LastWriteTime** property, +such as files in the file system `[System.Io.FileIO]`, to the **Start** parameter of `New-TimeSpan`. ```yaml Type: DateTime @@ -180,23 +215,28 @@ Aliases: LastWriteTime Required: False Position: 0 -Default value: None +Default value: Current date and time Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, +-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, +-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md). ## INPUTS ### System.DateTime -You can pipe a **DateTime** object that represents that start time to **New-TimeSpan**. + +You can pipe a **DateTime** object that represents that start time to `New-TimeSpan`. ## OUTPUTS ### System.TimeSpan -**New-TimeSpan** returns an object that represents the time span. + +`New-TimeSpan` returns an object that represents the time span. ## NOTES diff --git a/reference/6/Microsoft.PowerShell.Utility/New-TimeSpan.md b/reference/6/Microsoft.PowerShell.Utility/New-TimeSpan.md index 23ea8c3fd889..6e7e0a58909d 100644 --- a/reference/6/Microsoft.PowerShell.Utility/New-TimeSpan.md +++ b/reference/6/Microsoft.PowerShell.Utility/New-TimeSpan.md @@ -3,12 +3,11 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml keywords: powershell,cmdlet locale: en-us Module Name: Microsoft.PowerShell.Utility -ms.date: 06/09/2017 +ms.date: 5/1/2019 online version: http://go.microsoft.com/fwlink/?LinkId=821837 schema: 2.0.0 title: New-TimeSpan --- - # New-TimeSpan ## SYNOPSIS @@ -17,51 +16,88 @@ Creates a TimeSpan object. ## SYNTAX ### Date (Default) + ``` New-TimeSpan [[-Start] ] [[-End] ] [] ``` ### Time + ``` New-TimeSpan [-Days ] [-Hours ] [-Minutes ] [-Seconds ] [] ``` ## DESCRIPTION -The **New-TimeSpan** cmdlet creates a **TimeSpan** object that represents a time interval. + +The `New-TimeSpan` cmdlet creates a **TimeSpan** object that represents a time interval. You can use a **TimeSpan** object to add or subtract time from **DateTime** objects. -Without parameters, a **New-Timespan** command returns a timespan object that represents a time interval of zero. +Without parameters, a `New-TimeSpan` command returns a **TimeSpan** object that represents a time +interval of zero. ## EXAMPLES ### Example 1: Create a TimeSpan object for a specified duration -``` -PS C:\> $TimeSpan = New-TimeSpan -Hour 1 -Minute 25 -``` -This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in a variable named $TimeSpan. -It displays a representation of the **TimeSpan** object. +This command creates a **TimeSpan** object with a duration of 1 hour and 25 minutes and stores it in +a variable named `$TimeSpan`. It displays a representation of the **TimeSpan** object. -### Example 2: Create a TimeSpan object for a time interval +```powershell +$TimeSpan = New-TimeSpan -Hours 1 -Minutes 25 +$TimeSpan ``` -PS C:\> new-timespan -end (get-date -year 2010 -month 1 -day 1) + +```Output +Days : 0 +Hours : 1 +Minutes : 25 +Seconds : 0 +Milliseconds : 0 +Ticks : 51000000000 +TotalDays : 0.0590277777777778 +TotalHours : 1.41666666666667 +TotalMinutes : 85 +TotalSeconds : 5100 +TotalMilliseconds : 5100000 ``` -This example creates a new **TimeSpan** object that represents the interval between the time that the command is run and January 1, 2010. +### Example 2: Create a TimeSpan object for a time interval -This command does not require the *Start* parameter, because the default value of the *Start* parameter is the current date and time. +This example creates a new **TimeSpan** object that represents the interval between the time that +the command is run and January 1, 2010. -### Example 3: Get the date 90 days from the current date +This command does not require the **Start** parameter, because the default value of the **Start** +parameter is the current date and time. + +```powershell +New-TimeSpan -End (Get-Date -Year 2010 -Month 1 -Day 1) ``` -PS C:\> $90days = New-TimeSpan -Days 90 -PS C:\> (Get-Date) + $90days + +### Example 3: Get the date 90 days from the current date + +```powershell +$90days = New-TimeSpan -Days 90 +(Get-Date) + $90days ``` These commands return the date that is 90 days after the current date. ### Example 4: Discover the TimeSpan since a file was updated + +This command tells you how long it has been since the [about_remote](../Microsoft.PowerShell.Core/About/about_Remote.md) +help file was last updated. +You can use this command format on any file, or any other object that has a **LastWriteTime** +property. + +This command works because the **Start** parameter of `New-TimeSpan` has an alias of +**LastWriteTime**. When you pipe an object that has a **LastWriteTime** property to `New-TimeSpan`, +PowerShell uses the value of the **LastWriteTime** property as the value of the **Start** parameter. + +```powershell +Get-ChildItem $PSHOME\en-us\about_remote.help.txt | New-TimeSpan ``` -PS C:\> dir $pshome\en-us\about_remote.help.txt | New-TimeSpan + +```Output Days : 321 Hours : 21 Minutes : 59 @@ -72,20 +108,13 @@ TotalDays : 321.916230471907 TotalHours : 7725.98953132578 TotalMinutes : 463559.371879547 TotalSeconds : 27813562.3127728 -TotalMilliseconds : 27813562312.7728 PS C:\> # Equivalent to: - -PS C:\> New-TimeSpan -Start (dir $pshome\en-us\about_remote.help.txt).lastwritetime +TotalMilliseconds : 27813562312.7728 ``` -This command tells you how long it has been since the about_remote.help.txt file was last updated. -You can use this command format on any file, and on any other object that has a **LastWriteTime** property. - -This command works because the *Start* parameter of **New-TimeSpan** has an alias of LastWriteTime. -When you pipe an object that has a **LastWriteTime** property to **New-TimeSpan**, PowerShell uses the value of the **LastWriteTime** property as the value of the *Start* parameter. - ## PARAMETERS ### -Days + Specifies the days in the time span. The default value is 0. @@ -102,6 +131,7 @@ Accept wildcard characters: False ``` ### -End + Specifies the end of a time span. The default value is the current date and time. @@ -112,12 +142,13 @@ Aliases: Required: False Position: 1 -Default value: None +Default value: Current date and time Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` ### -Hours + Specifies the hours in the time span. The default value is zero. @@ -134,6 +165,7 @@ Accept wildcard characters: False ``` ### -Minutes + Specifies the minutes in the time span. The default value is 0. @@ -150,6 +182,7 @@ Accept wildcard characters: False ``` ### -Seconds + Specifies the length of the time span in seconds. The default value is 0. @@ -166,12 +199,14 @@ Accept wildcard characters: False ``` ### -Start + Specifies the start of a time span. -Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such as one from a Get-Date command. -The default value is the current date and time. +Enter a string that represents the date and time, such as "3/15/09" or a **DateTime** object, such +as one from a `Get-Date` command. The default value is the current date and time. -You can use *Start* or its alias, LastWriteTime. -The LastWriteTime alias lets you pipe objects that have a **LastWriteTime** property, such as files in the file system (System.Io.FileIO), to the Start parameter of **New-TimeSpan**. +You can use **Start** or its alias, **LastWriteTime**. +The **LastWriteTime** alias lets you pipe objects that have a **LastWriteTime** property, +such as files in the file system `[System.Io.FileIO]`, to the **Start** parameter of `New-TimeSpan`. ```yaml Type: DateTime @@ -180,23 +215,28 @@ Aliases: LastWriteTime Required: False Position: 0 -Default value: None +Default value: Current date and time Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, +-InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, +-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](../Microsoft.PowerShell.Core/About/about_CommonParameters.md). ## INPUTS ### System.DateTime -You can pipe a **DateTime** object that represents that start time to **New-TimeSpan**. + +You can pipe a **DateTime** object that represents that start time to `New-TimeSpan`. ## OUTPUTS ### System.TimeSpan -**New-TimeSpan** returns an object that represents the time span. + +`New-TimeSpan` returns an object that represents the time span. ## NOTES @@ -204,4 +244,4 @@ You can pipe a **DateTime** object that represents that start time to **New-Time [Get-Date](Get-Date.md) -[Set-Date](Set-Date.md) \ No newline at end of file +[Set-Date](Set-Date.md)