ISO format dates

I often create file names such as logs with the current date and was tired of having to create the date string for all my scripts, so created these quick functions which I added to my Profile.

function Get-ISODate { Get-Date -UFormat "%Y-%m-%d" }

I also use the following when requiring a further level of detail.

function Get-ISODateTime { Get-Date -uFormat "%Y-%m-%d-%H-%M-%S" }

Example usage:

[string]$path = "D:\LogFiles\"
[string]$logfile = "$path$(Get-ISODate).log"
$logfile
D:\LogFiles\2010-10-03.log

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.