header image

Date Formats–custom formats

Posted by: | June 9, 2011 | No Comment |

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.

under: PowerShellV2