Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Strings (re: Formatting DateTime)

Status
Not open for further replies.

crobin1

MIS
Aug 22, 2002
381
US
I saw Frink's post on formatting Date/Time and thought I'd throw this out. The -f format operator calls the .NET Format method on the System.String class. I know as Admins/non-coders seeing .NET leads to "but I'm not a programmer!". It can be helpful to dig through some of the documentation though.

In this case the solution to Frink's issue can be simplified to:
Code:
$datDateTimeFormatted = "{0:dd}/{0:MM}/{0:yyyy} {0:hh}:{0:mm}:{0:ss}" -f (Get-Date)
(or to quickly check interactively:)
Code:
"{0:dd}/{0:MM}/{0:yyyy}" -f (Get-Date)

Additional information can be found on Composite Formatting at and various links off of there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top