Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Get Date Without Time in PowerShell

June 8, 2024
in Blog, Powershell
0
ADVERTISEMENT

Table of Contents

By default, the Get-Date cmdlet in PowerShell returns the current date and time. Sometimes, you may need a [System.DateTime] object that contains the date without the time portion.

PS C:\> Get-Date

Thursday, June 6, 2024 6:15:47 PM

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

Use .ToString()

The first 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:

PS C:\> (Get-Date).ToString("M/d/yyyy")

6/6/2024

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:

PS C:\> (Get-Date).ToString("MM/dd/yyyy")

06/06/2024

This method is especially helpful if the date and time is stored in a variable.

PS C:\> $date = Get-Date
PS C:\> $date.ToString('MM/dd/yyyy')

06/06/2024

Formatting the Date

If you need to format the date, PowerShell allows you to specify the format using the -Format parameter. It’s a string representation of the date, without any time information.

PS C:\> Get-Date -Format "MM/dd/yyyy"

06/06/2024
PS C:\> Get-Date -Format "MM/dd/yyyy" | Get-Member

   TypeName: System.String

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.

PS C:\> Get-Date

Thursday, June 6, 2024 6:25:03 PM


PS C:\> (Get-Date).Date

Thursday, June 6, 2024 12:00:00 AM

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.

PS C:\> (Get-Date).Date | Get-Member

   TypeName: System.DateTime

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.

ADVERTISEMENT

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Delete Files Older Than a Specified Number of Days Using PowerShell

Next Post

How to Export Licensed Users with Last Sign-in Time in Microsoft 365

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory