Do you want to get-date without time in PowerShell? In this PowerShell tutorial, I will explain different “PowerShell get-date without time” methods with examples.
PowerShell get-date without time
Here are different ways to get-date without time in PowerShell.
Using Get-Date with DisplayHint Parameter
PowerShell provides the Get-Date
cmdlet, which is a versatile command used to retrieve the current date and time. To get only the date part, you can make use of the -DisplayHint
parameter.
$todayDate = Get-Date -DisplayHint Date
This PowerShell command will return the current date with the default date format, omitting the time portion.
Formatting the Date
If you need to format the date, PowerShell allows you to specify the format using the -Format
parameter.
$todayDate = Get-Date -Format "yyyy-MM-dd"
This command will return the date in the format of year-month-day, for example, “2024-01-04”. It’s a string representation of the date, without any time information.
Once you run the code, you can see the output in the below screenshot.
Creating a DateTime Object with Today’s Date Only
Sometimes, you may need a [System.DateTime]
object that contains today’s date without the time portion. To achieve this, you can use the Date
property of the DateTime
object returned by Get-Date
in PowerShell.
$todayDate = (Get-Date).Date
This command will create a [System.DateTime]
object with the time set to 00:00:00, effectively removing the time part but still leaving you with a DateTime
object that can be used in date calculations or comparisons.
Conclusion
Using the Get-Date
cmdlet in PowerShell to retrieve the current date without the time is straightforward. Here, I have explained different methods of how to get-date without time in PowerShell.
You may also like:
- PowerShell Get-Date Format
- PowerShell Get File Last Modified Date
- PowerShell Get-Date Minus 1 Day
- PowerShell If Date Is Older Than 30 Days
- PowerShell Get-date Format Milliseconds
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com