How to Format CreationTime in PowerShell (With Example)


You can use the following syntax in PowerShell to format the CreationTime property of files in a directory:

Get-ChildItem |
  Select-Object -ExpandProperty CreationTime |
  Get-Date -f 'yyyy-MM-dd'

This particular example will return the file creation date of each file in the current directory, formatted as yyyy-MM-dd.

Note that we use the -f operator to “format” the CreationTime property using a specific format.

The following example shows how to use this syntax in practice.

Example: How to Format CreationTime in PowerShell

We can use the following syntax to get a list of creation times for each file in our current directory:

Get-ChildItem | Select-Object CreationTime

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

By default, the creation times are formatted as MM/dd/yyyy hh:mm:ss AM/PM.

However, we can use the -f operator to instead format these creation times using a different format:

Get-ChildItem |
  Select-Object -ExpandProperty CreationTime |
  Get-Date -f 'yyyy-MM-dd'

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

PowerShell format CreationTime

Notice that the creation times for the files are now formatted as yyyy-MM-dd.

Feel free to specify any datetime format that you’d like with the -f operator.

For example, we could use the following syntax to format the creation times as yyyy-MM-dd hh:mm:

Get-ChildItem |
  Select-Object -ExpandProperty CreationTime |
  Get-Date -f 'yyyy-MM-dd hh:mm'

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

Notice that the creation times now include the hours and minutes in the datetime.

Related Tutorials

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

PowerShell: How to Use Get-ChildItem with Filter
PowerShell: How to Use Get-ChildItem to Get Full Path of Files
PowerShell: How to List Files in Directory by Date

Leave a Reply