Formatting

Dim sResult As String 
sResult = System.String.Format("{0:MM\/dd\/yyyy}", System.DateTime.Now())
sResult = "01/06/2002"
d 
D 
f 
F 
g 
G 
M,m 
Y,y 
t 
T 
s 
u 
U 
R,r 


You can also build you own custom number format by using any of the following special characters.

d 
dd 
ddd 
dddd 
M 
MM 
MMM 
MMMM 
y 
yy 
yyyy 
H 
HH 
h 
hh 
m 
mm 
s 
ss 
t 
ttAM / PM
z 
zz 
zzz 
/ 
: 
\ 


Formatting Dates


Dim dtDateTime As System.DateTime 
dtDateTime As New System.DateTime(2002, 1, 6, 18, 30, 20)



ToLongDateString

This format does not always display correctly and will depend on local settings.
It only displays the following format when the settings are US

System.DateTime dtDateTime; 
dtDateTime = new System.DateTime(2020,1,6,18,30,20);
dtDateTime.ToLongDateString = "Sunday, January 06, 2020"

When the settings are UK the format is as follows:

dtDateTime.ToLongDateString = "January 06, 2002" 


ToShortDateString

This format does not always display correctly and will depend on local settings.

dtDateTime.ToShortDateString = 01/06/2002 


ToString

Again there are 2 different ways

Dim sDateString As String 
sDateString = Now().ToString("dd mmm yy")
sDateString = System.DateTime.ToString(Now())


DateTimeFormatInfo

Defines how DateTime values are formatted and displayed
Added in .NET 2.0



Other Formats

dtDateTime.ToShortTimeString = 6:30 PM 
dtDateTime.ToLongTimeString = 6:30:20 PM
dtDateTime.ToFileTime = 126548334205000000
dtDateTime.ToOADate = 37262.7710706019
dtDateTime.ToUniversalTime = 1/6/2002 11:30:20 PM
dtDateTime.ToLocalTime = 1/6/2002 1:30:20 PM



© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

PrevNext