C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
PowerShell Get-DateThe Get-Date cmdlet in PowerShell displays the current date and time on the PowerShell console. This cmdlet gets a DateTime object. We can also use the Get-Date to generate and send the date and time character string to the other cmdlets or programs. SyntaxGet-Date [[-Date] <datetime>] [-Year <int>] [-Month <int>] [-Day <int>] [-Hour <int>] [-Minute <int>] [-Second <int>] [-Millisecond <int>] [-DisplayHint {Date | Time | DateTime}] [-Format <string>] [<CommonParameters>] Get-Date [[-Date] <datetime>] [-Year <int>] [-Month <int>] [-Day <int>] [-Hour <int>] [-Minute <int>] [-Second <int>] [-Millisecond <int>] [-DisplayHint {Date | Time | DateTime}] [-UFormat <string>] [<CommonParameters>] ParametersFollowing are the parameters used in Get-Date cmdlet: -Date This parameter allows you to specify a particular date and time in the cmdlet. By default, the get-date cmdlet returns the system date and time. In this parameter, time is optional if you do not specify it in the command, then the command returns 00:00:00. -Year This parameter is used to specify the year. Enter the value of a Year from 1 to 9999, which is followed by this parameter. -Month This parameter is used to specify the month of the year, which is displayed. Enter the value of a month from 1 to 12, which is followed by this parameter. -Day This parameter is used to specify the day of the month, which is displayed. Enter the value of a day from 1 to 31, which is followed by this parameter. If the specified value of the day in the cmdlet is greater than the number of days in the month, then the PowerShell adds the number of days to the month. -Hour This parameter is used to specify the hour. Enter the value of the hour from 0 to 23, which is followed by this parameter. -Minute This parameter is used to specify the minute. Enter the value of a minute from 0 to 59, which is followed by this parameter. -Second This parameter is used to specify the second. Enter the value of a second from 0 to 59, which is followed by this parameter. -Millisecond -Millisecond parameter was introduced in PowerShell version 3.0 and is used to specify the milliseconds in the date. Enter the value of millisecond from 0 to 999. -DisplayHint This parameter determines which value of date and time are displayed on the console. -Format This parameter shows the date and time in the format of the Microsoft .NET framework. With the starting of PowerShell version 5.0, for this parameter, we can use the following formats as its values:
-UFormat This parameter is used to display the date and time in the format of UNIX. This parameter outputs an object of a string. The specifiers of this parameter are preceded by a percent sign (%). ExamplesExample 1: Display the current date and time In this example, Get-Date cmdlet shows the current date and time of the system. Example 2: Display the current date In this example, the cmdlet Get-Date uses the -DisplayHint parameter with the value argument to get the date only. Example 3: Display the date and time with a .NET format specifier In this example, the Get-Date cmdlet uses the -Format parameter to display the current date and time with a .NET format specifier. In this example, we use the following format specifiers:
Example 4: Display only a month of the year In this example, the Get-Date cmdlet is used with the property month.
Next TopicIf Statement
|