Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Date to a formatted string in VB.net?

Tags:

There seems to be a million questions here on converting a string to a Date, but not vice-versa. When I convert a Date object to a string using mydate.toString I get a string in the format 16/01/2013 13:00:00.

But what I really want is 2013-01-16 13:00:00. I can't see any functions on the Date object that do this for me, do I need to use a regex or something instead?

like image 339
DisgruntledGoat Avatar asked Jan 16 '13 13:01

DisgruntledGoat


People also ask

How you can format a date in VB net?

Format Requirements You must enclose a Date literal within number signs ( # # ). You must specify the date value in the format M/d/yyyy, for example #5/31/1993# , or yyyy-MM-dd, for example #1993-5-31# . You can use slashes when specifying the year first.

What is FFF in date format?

The "fff" custom format specifier represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.

How do you format a date?

The United States is one of the few countries that use “mm-dd-yyyy” as their date format–which is very very unique! The day is written first and the year last in most countries (dd-mm-yyyy) and some nations, such as Iran, Korea, and China, write the year first and the day last (yyyy-mm-dd).


1 Answers

You can use the ToString overload. Have a look at this page for more info

So just Use myDate.ToString("yyyy-MM-dd HH:mm:ss")

or something equivalent

like image 180
Matt Wilko Avatar answered Oct 07 '22 21:10

Matt Wilko