I have searched a few pages on this (including MSDN) but have not quite reached a solution. I need to convert "16/04/2010 22:39:06" to "2010-04-16 22:39:06.034" (for example).
I have already written an SQL function to do this, but would rather do this in VB.NET if possible. The date value is coming from the Date Created information of a newly uploaded file:
Since the CreationTime property of a FileInfo object is a DateTime, you can use the DateTime.ToString method to control how the date converts to a string.
zoggling
Member
200 Points
317 Posts
Convert date and time format in vb.net
Apr 22, 2010 09:16 PM|LINK
I have searched a few pages on this (including MSDN) but have not quite reached a solution. I need to convert "16/04/2010 22:39:06" to "2010-04-16 22:39:06.034" (for example).
I have already written an SQL function to do this, but would rather do this in VB.NET if possible. The date value is coming from the Date Created information of a newly uploaded file:
Thanks in advance!
Convert date time format vb.net
mbanavige
All-Star
134964 Points
15421 Posts
ASPInsiders
Moderator
MVP
Re: Convert date and time format in vb.net
Apr 22, 2010 09:46 PM|LINK
Since the CreationTime property of a FileInfo object is a DateTime, you can use the DateTime.ToString method to control how the date converts to a string.
for example:
tbNewDateCreated.Text = MyFileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss.fff")
ignatandrei
All-Star
134913 Points
21619 Posts
Moderator
MVP
Re: Convert date and time format in vb.net
Apr 22, 2010 09:47 PM|LINK
dim dt as DateTime= DateTime.ParseExact("16/04/2010 22:39:06","dd/MM/yyyy HH:mm:dd",Nothing)
dim s as string= dt.ToString("yyyy-MM-dd HH:mm:dd")
zoggling
Member
200 Points
317 Posts
Re: Convert date and time format in vb.net
Apr 27, 2010 01:06 PM|LINK
Thank you for your replies, apologies for the late response. The first solution worked for me, thank you!