TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Get-Date

PowerShell Get-Date with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

PowerShell Get-Date

The 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.

Syntax

Get-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>]

Parameters

Following 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:

  • FileDate
  • FileDateUniversal
  • FileDateTime
  • FileDateTimeUniversal

-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 (%).

Examples

Example 1: Display the current date and time

PowerShell Get-Date

In this example, Get-Date cmdlet shows the current date and time of the system.

Example 2: Display the current date

PowerShell Get-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

PowerShell Get-Date

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:

  • dddd: Day of the Week
  • mm: Month of the Year
  • dd: Day of the Month
  • yyyy: Year in 4-digit format
  • HH:mm: Time is in the 24-hour format

Example 4: Display only a month of the year

PowerShell Get-Date

In this example, the Get-Date cmdlet is used with the property month.


Next TopicIf Statement




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf