PowerShell for Windows Admins

Jun 9 2011   3:14PM GMT

Date Formats–custom formats



Posted by: Richard Siddaway
Tags:
PowerShell v2

I’ve added examples of practically all of the custom elements that can be used in a date format

"d ShortDatePattern                                                :  {0} " -f (get-date -Format d )
"D LongDatePattern                                                 :  {0} " -f (get-date -Format D )
"f Full date and time (long date and short time)                   :  {0} " -f (get-date -Format f )
"F FullDateTimePattern (long date and long time)                   :  {0} " -f (get-date -Format F )
"g General (short date and short time)                             :  {0} " -f (get-date -Format g )
"G General (short date and long time)                              :  {0} " -f (get-date -Format G )
"m MonthDayPattern                                                 :  {0} " -f (get-date -Format m )
"M MonthDayPattern                                                 :  {0} " -f (get-date -Format M )
"o Round-trip date/time pattern always uses the invariant culture  :  {0} " -f (get-date -Format o )
"O Round-trip date/time pattern always uses the invariant culture  :  {0} " -f (get-date -Format O )
"r RFC1123Pattern always uses the invariant culture                :  {0} " -f (get-date -Format r )
"R RFC1123Pattern always uses the invariant culture                :  {0} " -f (get-date -Format R )
"s SortableDateTimePattern always uses the invariant culture       :  {0} " -f (get-date -Format s )
"t ShortTimePattern                                                :  {0} " -f (get-date -Format t )
"T LongTimePattern                                                 :  {0} " -f (get-date -Format T )
"u UniversalSortableDateTimePattern                                :  {0} " -f (get-date -Format u )
"U Full date and time – universal time                             :  {0} " -f (get-date -Format u )
"y YearMonthPattern                                                :  {0} " -f (get-date -Format y )
"Y YearMonthPattern                                                :  {0} " -f (get-date -Format Y )

"`nCustom Formats"
"d/M/y                                  :  {0} " -f (get-date -Format d/M/y )
"%d/%M/yy                               :  {0} " -f (get-date -Format d/M/yy )
"dd/MM/yyyy                             :  {0} " -f (get-date -Format dd/MM/yyyyy )
"dd/MM/yyyy %g                          :  {0} " -f (get-date -Format ‘dd/MM/yyyyy %g’)
"dd/MM/yyyy gg                          :  {0} " -f (get-date -Format ‘dd/MM/yyyyy gg’)
"dddd dd/MM/yyyy gg                     :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy gg’)
"dddd dd/MM/yyyy %h:m:s tt gg           :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy %h:m:s tt gg’)
"dddd dd/MM/yyyy hh:mm:s tt gg          :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy hh:mm:s tt gg’)
"dddd dd/MM/yyyy HH:mm:s gg             :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy HH:mm:s gg’)
"dddd dd/MM/yyyy HH:mm:s.ffff gg        :  {0} " -f (get-date -Format ‘dddd dd/MM/yyyyy HH:mm:s.ffff gg’)
"dddd dd MMM yyyy HH:mm:s.ffff gg       :  {0} " -f (get-date -Format ‘dddd dd MMM yyyyy HH:mm:s.ffff gg’)
"dddd dd MMMM yyyy HH:mm:s.ffff gg      :  {0} " -f (get-date -Format ‘dddd dd MMMM yyyyy HH:mm:s.ffff gg’)
"dddd dd MMMM yyyy HH:mm:s.ffff zz gg   :  {0} " -f (get-date -Format ‘dddd dd MMMM yyyyy HH:mm:s.ffff zz gg’)
"dddd dd MMMM yyyy HH:mm:s.ffff zzz gg  :  {0} " -f (get-date -Format ‘dddd dd MMMM yyyyy HH:mm:s.ffff zzz gg’)

The various custom elements can be combined in numerous other ways but these examples should show you how they all work.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: