EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Get-Date
Secondary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Get-Date

By Chirag NagarekarChirag Nagarekar

powershell getdate

Introduction to PowerShell Get-Date

Get-Date cmdlet in PowerShell is used to get the Date and Time of the System. It uses the local computer system’s date and time. Its data type is DateTime. The output format of the Date and Time depends on the computer’s cultural settings that can be determined by the below syntax and command.

Syntax:

Following are the syntax for PowerShell Get-Date:

Get-Date
[[-Date] <DateTime>] [-Year <Int32>] [-Month <Int32>] [-Day <Int32>] [-Hour <Int32>] [-Minute <Int32>] [-Second <Int32>] [-Millisecond <Int32>] [-DisplayHint <DisplayHintType>] [-Format <String>] [-UFormat <String>] [<CommonParameters>]

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Code:

(Get-Culture).DateTimeFormat

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,584 ratings)

Output:

PowerShell Get-Date - 1

Parameters of PowerShell Get-Date

The default output of the command Get-Date is displayed in the below format.

Code:

get-date

Output:

PowerShell Get-Date - 2

Below parameters are used by Get-Date cmdlet to format the command output.

1. Date

When you use Date as a property like (Get-Date). Date, it specifies the date and time both. It displays the time 00:00:00 by default along with the system’s current date. Time property will give you the current system time. The output will be the DateTime data type only. And when you specify –Date parameter and date followed by it, it displays the specific date. For example Get-Date –Date “01/01/2010 22:00:00”. This action will not change the date/time of the system.

2. Year

When you specify Year as a property like (Get-Date). The year will provide the current system year. The output of the command is Int32 datatype. You can use –Year parameter to display the different year.

3. Month

When Month is mentioned as property like (Get-Date). Month it will display the current system’s month as an output. The output will be in the Int32 data type format. You can use –Month parameter to display the different month. The value should be between 1 to 12.

4. Day

When Day is specified as a property like (Get-Date).Day, it will display the current system’s day as an output. The output will be in the Int32 format. You can use –Day parameter to display a different day. The value should be between 1 to 31.

5. Hour

When Hour is specified as a property like (Get-Date).Hour, it will display the current system’s hour as an output. The output will be in the Int32 format. You can use –Hour parameter to display the different hours. The value should be between 1 to 24.

6. Minute

When Minute is specified as a property like (Get-Date).Minute, it will display the current system’s minute as an output. The output will be in the Int32 format. You can use –Minute parameter to display the different minutes. The values should be between 1 to 60.

7. Second

This parameter is to set and display the seconds of the current system and output will be in Int32 format. When you set seconds, it will just a temporary display of the seconds not setting it permanently. The value should be 1 to 60.

8. Millisecond

This parameter is to set and display the millisecond of the current system and output will be in Int32 format. When you set milliseconds, it will just a temporary display of the seconds not the setting permanently. The value should be 1 to 999.

9. DisplayHint

This parameter displays only Date or only Time or DateTime, depends on the specified argument.

Accepted values are,

  • Date: Display only system current date.
  • Time: Display the only system current time.
  • DateTime: Display only system DateTime

Examples to Implement PowerShell Get-Date

Below are the examples that implement PowerShell Get-Date:

Example #1

The get-date command will give you the current Date and Time of the system. A similar output can be fetched by the below commands.

Code:

(Get-Date).DateTime
Get-Date -DisplayHint DateTime

Output:

PowerShell Get-Date - 3

Example #2

To display the Date, you can use two commands.

1. (Get-Date).Date: This command will display the date along with 00:00:00 or 12:00:00 time format.

Code:

(Get-Date).Date

Output:

PowerShell Get-Date - 4

2. Get-Date -DisplayHint Date: This command will display only the date of the system.

Code:

Get-Date -DisplayHint Date

Output:

PowerShell Get-Date - 5

3. To display the Time, below command can be used

Code:

Get-Date -DisplayHint Time

Output:

PowerShell Get-Date - 6

Example #3

Below properties are supported by the Get-Date command.

PowerShell Get-Date - 7

Above each property has the following commands:

Code:

$d = Get-Date
"Date :  " + $d.Date
"Day : " + $d.Day
"Day Of Week : "+ $d.DayOfWeek
"Day of Year : "+ $d.DayOfYear
"Hour : " + $d.Hour
"Kind : " + $d.Kind
"MilliScond : " + $d.Millisecond
"Minute : " +$d.Minute
"Second : " +$d.Second
"Ticks : " + $d.Ticks
"Time Of Day : " + $d.TimeOfDay
"Year : " + $d.Year

Output:

PowerShell Get-Date - 8

Example #4

To format the output using -Format parameter, Here, we will display Date in “MMddyyyy”

Code:

Get-Date -Format "MMddyyyy"

Output:

PowerShell Get-Date - 9

You can also put the separator between them, For example,

Code:

Get-Date -Format "MM-dd-yyyy"
Get-Date -Format "MM/dd/yyyy"

Outputs:

PowerShell Get-Date - 10

All of the above outputs will be in String format.

Example #5

To get the output including hours, minutes and seconds,

Code:

Get-Date -Format "ddMMyyyy HH:mm:ss"

Outputs:

including hours, minutes and seconds

Example #6

You can use the Get-Date command to temporarily change in time or date. For example, the below command will display the year 2030 in output, the rest date and time will remain the same.

Code:

Get-Date -Year 2030

Output:

2030 in output

Similarly, you can change the day, hour, date, minute, seconds, etc.

Example #7

To change output in UFormat, The table mentioned below will describe UFormat.

Code:

Get-Date -UFormat "%m%d%Y"

Output:

UFormat

Similarly, you can use different combinations below.

combinations

Example #8

There are also methods available for Get-Date as below.

PowerShell Get-Date - 15

If you want to get the Date and time after 3 days,

Code:

(Get-Date).AddDays(+3)

Output:

Date and time after 3 days

To get the date/time of 2 days back,

Code:

(Get-Date).AddDays(-2)

Output:

To get the date/time of 2 days back,

Similarly, you can use other methods to add/minus the hours, months, seconds, etc with the methods described in the snapshot above. You can also check if daylight saving is enabled for the current date with IsDaylightSavingTime()  and output will be in the boolean format (True or False).

Code:

(Get-Date).IsDaylightSavingTime()

Output:

PowerShell Get-Date - 18

Conclusion

Get-Date is useful when formatting outputs that involve date and time. You can extract data by modifying dates as well, which is assigned to a temporary variable. To set the date of the system, use the Set-Date command.

Recommended Articles

This is a guide to PowerShell Get-Date. Here we discuss syntax, the parameters are used by Get-Date cmdlet and the examples that implement PowerShell Get-Date. You can also go through our other related articles to learn more –

  1. PowerShell Format-Table
  2. If Statement in PowerShell
  3. PowerShell Test-Path | Examples | Parameters
  4. Examples to Implement PowerShell New-Item
  5. PowerShell Rename-Item | How to Implement?
  6. Date in HTML with Examples
  7. Parameters of PowerShell Convert to String
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
Data Visualization Training (15 Courses, 5+ Projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more