How to Get Date Without Time in PowerShell


By default the Get-Date cmdlet in PowerShell returns the current date and time.

If you would like to only retrieve the date without the time, you can use one of the following methods to do so:

Method 1: Use (Get-Date).ToString()

(Get-Date).ToString("M/d/yyyy")

Method 2: Use (Get-Date).Date

(Get-Date).Date

Both methods will return the current date without the time.

The following examples show how to use each method in practice.

Example 1: Use (Get-Date).ToString()

One way to get the current date without the time in PowerShell is by using the ToString() method to simply format the current date and time using M/d/yyyy as the date format:

We can use the following syntax to do so:

(Get-Date).ToString("M/d/yyyy")

The following screenshot shows how to use this syntax in practice:

PowerShell Get-Date without time

This returns 3/5/2024, which is the current date when this article is being written.

Note that the format M/d/yyyy specifies that only one digit should be used for the month and day if they month and day only contain a single digit.

If you would like to display two digits for the month and day, you can use the MM/dd/yyyy format instead:

(Get-Date).ToString("MM/dd/yyyy")

The following screenshot shows how to use this syntax in practice:

This returns 03/05/2024.

Example 2: Use (Get-Date).Date

Another way to get the current date without the time in PowerShell is by using the .Date property of the Get-Date cmdlet.

We can use the following syntax to do so:

(Get-Date).Date

The following screenshot shows how to use this syntax in practice:

This returns Tuesday, March 5, 2024 12:00:00 AM, which is the current date when this article is being written with the time component set to zero.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

How to Compare Dates in PowerShell
How to Format a DateTime in PowerShell
How to Calculate Date Difference in PowerShell

Leave a Reply