Reference: Number and Date Formats

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

You can modify the display format for numbers and dates in Visual Studio LightSwitch by setting the Format Pattern property. The following sections show the notation and rules for that property in addition to examples of format strings that are commonly used.

System_CAPS_ICON_note.jpg Note

The examples assume that the application’s Culture property is set to English (United States). If you change the Culture property in Visual Studio LightSwitch, culture-specific formatting will be applied only if the culture setting of the local machine matches.

  1. Numeric Formats

  2. Standard Numeric Format Strings

  3. Custom Numeric Format Strings

  4. Date and Time Formats

  5. Standard Date and Time Format Strings

  6. Custom Date and Time Format Strings

  7. Formatting Guids

You can use numeric format strings to format the Decimal, Double, Integer, Long Integer, and Short Integer data types. A standard numeric format string takes the form Axx, where A is an alphabetic character that's called the format specifier, and xx is an optional integer that's called the precision specifier. The precision specifier ranges from 0 to 99 and affects the number of digits in the result.

System_CAPS_ICON_note.jpg Note

For the Decimal data type, the precision specifier can't be larger than the Scale property value that's specified for the field. For the Integer, Long Integer, and Short Integer types, no precision specifier should be used.

You can also create a custom numeric format string, which consists of one or more custom numeric specifiers, to define how to format numeric data. Any numeric format string that contains more than one alphabetic character, including white space, is interpreted as a custom numeric format string.

Standard Numeric Format Strings

The following table lists the standard numeric format specifiers and displays sample output that each format string produces. For more information, see Standard Numeric Format Strings.

Format specifierNameRaw Value, Data TypeFormat StringDisplayed Result
"C" or "c"Currency123.456, Double

123.456, Double

123.456, Double

123, Integer
C

C2

C3

C
$123.46

$123.46

$123.456

$123.00
"D" or "d"Decimal1234, Integer

1234, Short Integer

-1234, Long Integer
D

D6

D6
1234

001234

-001234
"E" or "e"Exponential (scientific)1052.0329112756, Double

-1052.0329112756, Double
E

E2
1.052033E+003

-1.05e+003
"F" or "f"Fixed-point1234.567, Double

1234, Decimal

-1234.56, Double
F

F1

F4
1234.57

1234.0

-1234.5600
"G" or "g"General-123.456, Double

123.4546, Double

-1.234567890e-25, Double
G

G4

G
-123.456

123.5

--1.23456789E-25
"N" or "n"Number1234.567, Double

1234, Integer

-1234.56, Double
N

N

N
1,234.57

1,234.0

-1,234.560
"P" or "p"Percent1, Double

-0.39678, Double
P

P1
100.00 %

-39.7 %
"R" or "r"Round-trip123456789.12345678, Double

-1234567890.12345678, Double
R

R
123456789.12345678

-1234567890.1234567
"X" or "x"Hexadecimal255, Integer

-1, Integer

255, Integer

-1, Integer
X

X

X4

X4
FF

ff

00ff

-00FF

Custom Numeric Format Strings

The following table describes the custom numeric format specifiers and displays sample output that each format string produces. For more information, see Custom Numeric Format Strings.

Format specifierNameRaw Value, Data TypeFormat StringDisplayed Result
"0"Zero placeholder1234.5678, Double

0.45678, Double
00000

0.00
01235

0.46
"#"Digit placeholder1234.5678, Double

0.45678, Double
#####

#.##
1235

.46
"."Decimal point0.45678, Double0.000.46
","Group separator and number scaling2147483647, Integer

2147483647, Integer
##,#

#,#,,
2,147,483,647

2,147
"%"Percentage placeholder0.3697, Double

0.3697, Double
%#0.00

##.0 %
%36.97

37.0 %
"‰"Per mille placeholder0.03697, Double#0.00‰36.97‰
"E0"

"E+0"

"E-0"

"e0"

"e+0"

"e-0"
Exponential notation987654, Double

1503.92311, Double

1.8901385E-16 ("0.0e+00"), Double
#0.0e0

0.0##e+00

0.0e+00
98.8e4

1.504e+03

1.9e-16
\Escape character987654, Integer\###00\##987654#
'string'

"string"
Literal string delimiter68, Integer

68, Integer
# ' degrees'

#” degrees”
68 degrees

68 degrees
;Section separator12.345, Double

0, Double

-12.345, Double

12.345, Double

0, Double

-12.345, Double
#0.0#;(#0.0#);-\0-

#0.0#;(#0.0#);-\0-

#0.0#;(#0.0#);-\0-

#0.0#;(#0.0#)

#0.0#;(#0.0#)

#0.0#;(#0.0#)
12.35

-0-

(12.35)

12.35

0.0

(12.35)
OtherAll other characters68, Integer# °68 °

Date and Time Formats

You can use date and time format strings format the Date and Date Time data types. A standard date and time format string uses a single format specifier to define the text representation of a date and time value. Any date and time format string that contains more than one character, including white space, is interpreted as a custom date and time format string.

Standard Date and Time Format Strings

The following table describes the standard date and time format specifiers. For more information, see Standard Date and Time Format Strings.

Format specifierDescriptionRaw Value (Date Time)Format StringDisplayed Result
"d"Short date pattern.6/15/2009 1:45:30 PMd6/15/2009
"D"Long date pattern.6/15/2009 1:45:30 PMDMonday, June 15, 2009
"f"Full date/time pattern (short time).6/15/2009 1:45:30 PMfMonday, June 15, 2009 1:45 PM
"F"Full date/time pattern (long time).6/15/2009 1:45:30 PMFMonday, June 15, 2009 1:45:30 PM
"g"General date/time pattern (short time).6/15/2009 1:45:30 PMg6/15/2009 1:45 PM
"G"General date/time pattern (long time).6/15/2009 1:45:30 PMG6/15/2009 1:45:30 PM
"M", "m"Month/day pattern.6/15/2009 1:45:30 PMMJune 15
"O", "o"Round-trip date/time pattern.6/15/2009 1:45:30 PMO2009-06-15T13:45:30.0900000
"R", "r"RFC1123 pattern.6/15/2009 1:45:30 PMRMon, 15 Jun 2009 20:45:30 GMT
"s"Sortable date/time pattern.6/15/2009 1:45:30 PMs62009-06-15T13:45:30
"t"Short time pattern.6/15/2009 1:45:30 PMt1:45 PM
"T"Long time pattern.6/15/2009 1:45:30 PMT1:45:30 PM
"u"Universal sortable date/time pattern.6/15/2009 1:45:30 PMu6/15/2009 1:45:30 PM -> 2009-06-15 20:45:30Z
U"Universal full date/time pattern.6/15/2009 1:45:30 PMUMonday, June 15, 2009 8:45:30 PM
"Y", "y"Year/month pattern.6/15/2009 1:45:30 PMYJune, 2009

Custom Date and Time Format Strings

The following table describes the custom date and time format specifiers. For more information, see Custom Date and Time Format Strings.

Format specifierDescriptionRaw Value (Date Time)Format StringDisplayed Result
"d"The day of the month, from 1 through 31.6/1/2009 1:45:30 PM

6/15/2009 1:45:30 PM
d

d
1

15
"dd"The day of the month, from 01 through 31.6/1/2009 1:45:30 PM

6/15/2009 1:45:30 PM
dd

dd
01

15
"ddd"The abbreviated name of the day of the week.6/15/2009 1:45:30 PMdddMon
"dddd"The full name of the day of the week.6/15/2009 1:45:30 PMddddMonday
"f"The tenths of a second in a date and time value.6/15/2009 13:45:30.617

6/15/2009 13:45:30.050
f

f
6

0
"ff"The hundredths of a second in a date and time value.6/15/2009 13:45:30.617

6/15/2009 13:45:30.005
ff

ff
61

00
"fff"The milliseconds in a date and time value.6/15/2009 13:45:30.617

6/15/2009 13:45:30.0005
fff

fff
617

000
"ffff"The ten thousandths of a second in a date and time value.6/15/2009 13:45:30.6175

6/15/2009 13:45:30.00005
ffff

ffff
6175

0000
"fffff"The hundred thousandths of a second in a date and time value.6/15/2009 13:45:30.61754

6/15/2009 13:45:30.000005
fffff

fffff
61754

00000
"ffffff"The millionths of a second in a date and time value.6/15/2009 13:45:30.617542

6/15/2009 13:45:30.0000005
ffffff

ffffff
617542

000000
"fffffff"The ten millionths of a second in a date and time value.6/15/2009 13:45:30.6175425

6/15/2009 13:45:30.0001150
fffffff

fffffff
6175425

0001150
"F"If non-zero, the tenths of a second in a date and time value.6/15/2009 13:45:30.617

6/15/2009 13:45:30.050
F

F
6

(no output)
"FF"If non-zero, the hundredths of a second in a date and time value.6/15/2009 13:45:30.617

6/15/2009 13:45:30.005
FF

FF
61

(no output)
FFF"If non-zero, the milliseconds in a date and time value.6/15/2009 13:45:30.617

6/15/2009 13:45:30.0005
FFF

FFF
617

(no output)
"FFFF"If non-zero, the ten thousandths of a second in a date and time value.6/1/2009 13:45:30.5275

6/15/2009 13:45:30.00005
FFFF

FFFF
5275

(no output)
"FFFFF"If non-zero, the hundred thousandths of a second in a date and time value.6/15/2009 13:45:30.61754

6/15/2009 13:45:30.000005
FFFFF

FFFFF
61754

(no output)
"FFFFFF"If non-zero, the millionths of a second in a date and time value.6/15/2009 13:45:30.617542

6/15/2009 13:45:30.0000005
FFFFFF

FFFFFF
617542

(no output)
"FFFFFFF"If non-zero, the ten millionths of a second in a date and time value.6/15/2009 13:45:30.6175425

6/15/2009 13:45:30.0001150
FFFFFFF

FFFFFFF
6175425

000115
"g", "gg"The period or era.6/15/2009 1:45:30 PMgA.D.
"h"The hour, using a 12-hour clock from 1 to 12.6/15/2009 1:45:30 AM

6/15/2009 1:45:30 PM
h

h
1

1
"hh"The hour, using a 12-hour clock from 01 to 12.6/15/2009 1:45:30 AM

6/15/2009 1:45:30 PM
hh

hh
01

01
"H"The hour, using a 24-hour clock from 0 to 23.6/15/2009 1:45:30 AM

6/15/2009 1:45:30 PM
H

H
1

13
"HH"The hour, using a 24-hour clock from 00 to 23.6/15/2009 1:45:30 AM

6/15/2009 1:45:30 PM
HH

HH
01

13
m"The minute, from 0 through 59.6/15/2009 1:09:30 AM

6/15/2009 1:29:30 PM
m

m
9

29
"mm"The minute, from 00 through 59.6/15/2009 1:09:30 AM

6/15/2009 1:29:30 PM
mm

mm
09

29
"M"The month, from 1 through 12.6/15/2009 1:45:30 PMM6
"MM"The month, from 01 through 12.6/15/2009 1:45:30 PMMM06
"MMM"The abbreviated name of the month.6/15/2009 1:45:30 PMMMMJun
"MMMM"The full name of the month.6/15/2009 1:45:30 PMMMMMJune
"s"The second, from 0 through 59.6/15/2009 1:45:09 PMs9
"ss"The second, from 00 through 59.6/15/2009 1:45:09 PMss09
"t"The first character of the AM/PM designator.6/15/2009 1:45:30 PMtP
"tt"The AM/PM designator.6/15/2009 1:45:30 PMttPM
"y"The year, from 0 to 99.6/15/2009 1:45:30 PMy9
"yy"The year, from 00 to 99.6/15/2009 1:45:30 PMyy09
"yyy"The year, with a minimum of three digits.1/1/0001 12:00:00 AM

6/15/2009 1:45:30 PM
yyy

yyy
001

2009
"yyyy"The year as a four-digit number.6/15/2009 1:45:30 PMyyyy2009
"yyyyy"The year as a five-digit number.6/15/2009 1:45:30 PMyyyyy02009
"z"Hours offset from UTC, with no leading zeros.6/15/2009 1:45:30 PM -07:00z-7
"zz"Hours offset from UTC, with a leading zero for a single-digit value.6/15/2009 1:45:30 PM -07:00zz-07
"zzz"Hours and minutes offset from UTC.6/15/2009 1:45:30 PM -07:00zzz-07:00
:"The time separator.6/15/2009 1:45:30 PMhh:mm01:45
"/"The date separator.6/15/2009 1:45:30 PMMM/dd6/15
"string"

'string'
Literal string delimiter.6/15/2009 1:45:30 PM

6/15/2009 1:45:30 PM
"arr:" h:m t

'arr:' h:m t
arr: 1:45 P

arr: 1:45 P
%Defines the following character as a custom format specifier.6/15/2009 1:45:30 PM%h1
\The escape character.6/15/2009 1:45:30 PMh \h1 h
Any other characterThe character is copied to the result string unchanged.6/15/2009 1:45:30 AMarr hh:mm tarr 01:45 A

Formatting Guids

The following table describes format specifiers for the Guid data type.

FormatDescriptionRaw Value (Guid)Format StringDisplayed Result
NDisplays 32 characters.3261a3cfc18f4747b957e5264b6a430cN3261a3cfc18f4747b957e5264b6a430c
DDisplays 32 characters separated by hyphens.3261a3cfc18f4747b957e5264b6a430cD3261a3cf-c18f-4747-b957-e5264b6a430c
BDisplays 32 characters separated by hyphens and enclosed in braces.3261a3cfc18f4747b957e5264b6a430cB{3261a3cf-c18f-4747-b957-e5264b6a430c }
PDisplays 32 characters separated by hyphens and enclosed in parentheses.3261a3cfc18f4747b957e5264b6a430cP(3261a3cf-c18f-4747-b957-e5264b6a430c)
XFour hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values enclosed in another set of braces.3261a3cfc18f4747b957e5264b6a430cX{0x3261a3cf,0xc18f,0x4747,{0xb0,0x57,0xe5,0x26,0x4b,0x6a,0x43,0x0c}}

How to: Format Numbers and Dates
Data: The Information Behind Your Application
Formatting Types

Show: