EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Get-Date
 

PowerShell Get-Date

Chirag Nagarekar
Article byChirag Nagarekar
EDUCBA
Reviewed byRavi Rathore

Updated March 24, 2023

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.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

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

Code:

(Get-Culture).DateTimeFormat

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

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

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

EDUCBA

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

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

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

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

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

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW