Custom DateTime Formatting


Custom Date/Time Formatting

Table 13.6 describes the custom format specifiers and examples of output. Note how the percent sign ( % ) converts standard to custom specifiers. For example, d specifies short date pattern, but %d specifies day of the month. When % is used with a character not reserved for custom formatting, the character displayed is literal. For example, a format string %n results in the output n

Table 13.6. Custom Date/Time Formatting

Format Specificer

Description

Output of Value=CDate("1/2/2003 23:59:11.15")

%d

Displays the current day of the month, measured as a number between 1 and 31, inclusive. Single digit only (1-9) displayed as a single digit.

2

dd

Displays the current day of the month, measured as a number between 1 and 31, inclusive. Single digit only (1-9) is prefixed with a preceding 0 (01-09).

02

ddd

Displays the abbreviated name of the day specified.

Thu

dddd(plus any number of additional "d" characters

Displays the full name of the day specified.

Thursday

f to fffffff

Displays seconds fractions represented in one to seven digits.

1 to 1500000

g or gg or any number of additional "g" characters

Displays the era (A.D., for example).

A.D.

%h

Displays the hour for the specified value in 12- hour format (undistinguished AM/PM, range 1-12). No rounding occurs; that is, a value of 4:45 returns 4.

11

hh plus any number of additional "h" characters

Same as above, but a single digit hour (1-9) is preceded with 0 (01-09).

11

%H

Displays the hour for the specified value in 24-hour format (the range 0-23). The hour represents whole hours passed since midnight (displayed as 0). If the hour is a single digit (0-9), it is displayed as a single digit.

23

HH, HH (plus any number of additional "H" characters)%m

Same as above, but a single digit hour(1-9) is preceded with 0 (01-09).

23

%m

Displays the minute for the specified value in the range 0-59. The minute represents whole minutes passed since the last hour. If the minute is a single digit (0-9), it is displayed as a single digit.

59

mm, mm (plus any number of dditional "m" characters)

Same as above. A single digit minute (0-9) is formatted with a preceding 0 (01-09).

59

%M

Displays the month, measured as a number between 1 and 12, inclusive. If the month is a single digit (1-9), it is displayed as a single digit.

1

MM

Same as above. A single digit month (1-9) is formatted with a preceding 0 (01-09).

01

MMM

Displays the abbreviated name of the month for the specified value.

Jan

MMMM

Displays the full name of the month for the specified value.

January

%s

Displays the seconds for the specified value in the range 0-59. The second represents whole seconds passed since the last minute. If the second is a single digit (0-9), it is displayed as a single digit only.

11

ss, ss (plus any number of additional "s" characters)

Same as above. A single digit second (0-9) is formatted with a preceding 0 (01-09).

11

%t

Displays the first character of the A.M./P.M. designator for the specified value.

P

tt, tt (plus any number of additional "t" characters)

Displays the A.M./P.M. designator for the specified value.

PM

%y

Displays the year for the specified value as a maximum two-digit number. The first two digits of the year are omitted. If the year is a single digit (1-9), it is displayed as a single digit.

3

yy

Same as above. A single digit year (1-9) is formatted with a preceding 0 (01-09).

03

yyyy

Displays the year for the specified value, including the century. If the year is less than four digits, 0s are added to the left to display four digits.

2003

%z

Displays the time zone offset for the system's current time zone in whole hours only. The offset is always displayed with a leading sign, which indicates hours ahead of Greenwich mean time (+) or behind Greenwich mean time (-). The range of values is -12 to +13. Value is affected by daylight savings time.

-6 Note:-6 offset is for central standard time.

zz

Same as above. Single digit is formatted with a preceding 0 (00-09).

-06

zzz, zzz (plus any number of additional "z" characters)

Same as above, but displays hours and minutes. The range of values is -12:00 to +13:00. Single digit offset (0-9) is formatted with a preceding 0 (00-09).

-06:00

:

Displays time separator.

 

/

Displays date separator.

 

"or'

Displays the literal value of a string enclosed .

 

\

Displays the next character as a literal. Cannot be used to create an escape sequence.

 

Additional information about custom date/time format strings can be found in the .NET Framework Developer's Guide at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcustomdatetimeformatstrings.asp.



Microsoft SQL Server 2005 Reporting Services
Microsoft SQL Server 2005 Reporting Services
ISBN: 0672327996
EAN: 2147483647
Year: 2004
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net