PowerShell is Microsoft’s automation and scripting platform. It’s a .NET Framework-based scripting language as well as an interactive command environment. PowerShell consists of a set of commands that perform specific functions. Just like any reasonable programming language, PowerShell can accomplish a lot of tasks. Displaying the current date is another simple function that PowerShell does effortlessly.

Using the “Get-Date” command, you can find the current date, format dates, tomorrow’s date, and a lot more with PowerShell. It also offers you various options for showing dates in a particular manner. This article will show you how to get the current date in PowerShell using different methods. So let’s begin:

What is Get-Date in PowerShell?

The Get-Date cmdlet is a lightweight command used in PowerShell. This command returns a DateTime object that displays the current date or a custom date. Get-Date supports a variety of UNIX and .NET date and time formats. It can generate a date or time character string, which can then be sent to other programs or commands.

On your local system, utilize the Get-Date cmdlet for getting the current date and time:

You can utilize Get-Date when you want to use “Date” as an attribute. The command will retrieve both the date and the time. It is set to show the system’s current date and time in the format “00:00:00” by default. The retrieved date and time settings depend on your system’s cultural settings:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-209.png" data-lazy- height="254" src="data:image/svg xml,” width=”860″>

Getting current date and time elements in PowerShell

You can use the “-DisplayHint” parameter in the “Get-Date” command to only get the current date of your local system. Do you want to give this strategy a shot? In your PowerShell, type the following command:

> Get-Date -DisplayHint Date

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-210.png" data-lazy- height="194" src="data:image/svg xml,” width=”843″>

To only view the current time of your system, specify the “Time” attribute in the “-DisplayHint” parameter:

> Get-Date -DisplayHint Time

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-211.png" data-lazy- height="176" src="data:image/svg xml,” width=”840″>

If you want to get the current date and time both in your PowerShell, then add “DateTime” in the same “Get-Date” command along with the “-DisplayHint” parameter:

> Get-Date -DisplayHint DateTime

It will show you the following output:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-212.png" data-lazy- height="166" src="data:image/svg xml,” width=”843″>

View the Get-Date Format-List

Although the “Get-Date” cmdlet appears only to return the current time and date, it can provide more information. Check out the format list of the “Get-Date” cmdlet to have an idea of what we are talking about:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-213.png" data-lazy- height="347" src="data:image/svg xml,” width=”715″>

Use UFormat Specifier for getting current date and time

UFormat specifiers are also used for output format customization. Following are some UFormat specifiers with their definitions:

%A“: This UFormat specifier will retrieve the day of the week with the full name.

%m”: Use this specifier to get the month number:

%d”: “%d” will show the month’s day in two digits.

%Y“: This UFormat specifier will show you the current year in four-digit format.

%R“: Use this specifier for displaying time in 24-hour format without seconds.

%Z“: “%Z” denotes a time zone offset from the Universal Time Coordinate (UTC).

In PowerShell, type this command to get the current time and date according to the specific UFormat:

> Get-Date -UFormat “%A %m/%d/%Y %R %Z”

This command will also return the output as a String object.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-214.png" data-lazy- height="169" src="data:image/svg xml,” width=”841″>

Use .Net format Specifier for getting current date and time

Get-Date” utilizes various format specifiers to customize its output, .Net is one of them. Now, let’s have a look at some .net specifiers:

dddd”: This specifier will get the day of the week (full name).

MM”: It will show you the month number.

dd”: “dd” will show the month’s day in two digits.

yyyy“: This .Net specifier will show you the current year in four-digit format.

HH:mm“: Use this specifier for displaying time in 24-hour format without seconds.

K”: This specifier denotes a time zone offset from the Universal Time Coordinate (UTC).

According to your .Net specifiers, write out this command in your PowerShell for getting the current date and time:

> Get-Date -Format “dddd MM/dd/yyyy HH:mm K”

The execution of the above-given command will return a String.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-215.png" data-lazy- height="152" src="data:image/svg xml,” width=”843″>

Get a date’s day in PowerShell

PowerShell is also capable of displaying you a date’s day. For that, it utilizes three parameters: “-Year,” “-Month,” and “-Day.” For example, the below-given command will retrieve your Gregorian calendar’s numeric day of October 03, 2022.

gt; (Get-Date -Year 2022 -Month 10 -Day 03).DayOfYear

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-216.png" data-lazy- height="226" src="data:image/svg xml,” width=”929″>

Adding Hours in Current system date in PowerShell

You can also perform the arithmetic operation of adding hours in the current date. Specify the total number of hours as a parameter in the “AddHours()” function.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-217.png" data-lazy- height="188" src="data:image/svg xml,” width=”840″>

Get Yesterday’s date in PowerShell

Utilize the “AddDays()” function and specify “-1” as a parameter for this function. Calling the “AddDays()” function with these specified settings will let you display Yesterday’s date in your PowerShell.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-218.png" data-lazy- height="159" src="data:image/svg xml,” width=”834″>

Check whether a date is set for daylight savings time

In the following example, we’ll see if the date we’ve mentioned has been set for daylight savings time. The “DST” variable will store the value returned by the “Get-Date” cmdlet. After that, it will call the “IsDayLightSavingTime()” boolean function. This function will answer your question in True or False.

> $DST = Get-Date

> $DST.IsDaylightSavingTime()

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-219.png" data-lazy- height="175" src="data:image/svg xml,” width=”842″>

More examples of Get-Date formats

Adding “-Format g” as a parameter in your Get-Date command will show you the current date and time in a short format:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-220.png" data-lazy- height="186" src="data:image/svg xml,” width=”840″>

Utilize the “-Format t” option if you only want to get the current time in a short format:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-221.png" data-lazy- height="150" src="data:image/svg xml,” width=”840″>

Similarly, you can also retrieve only the current date of your system in short format by using the “-Format d” option.

It will return the date in a certain format:

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-222.png" data-lazy- height="176" src="data:image/svg xml,” width=”841″>

Use the “U” format option to retrieve the current time and date in Universal Time format.

<img data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/word-image-223.png" data-lazy- height="171" src="data:image/svg xml,” width=”842″>

Conclusion

Is there any method to get the current date in PowerShell? You will be amazed to know that answer to this question is simple than the question itself seems. PowerShell utilizes a Get-Date cmdlet to get the current date of your local system. This command is also used for formatting outputs that involve date and time. We have shown you various formats for getting the current date in PowerShell. Moreover, different customization methods are also provided in this article.

About the author

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/talha-150×150.jpg61132d4c10522.jpg" height="112" src="data:image/svg xml,” width=”112″>

Talha Saif Malik

Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.