How to convert string date to yyyy mm dd format in C#
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Program { static void Main(string[] args) { //this line create a datetime variable. DateTime now = DateTime.Now; Console.WriteLine("now: " + now); //format date in string using ToString method. Console.WriteLine("date format using TosString method: " + now.ToString("yyyy-MM-dd")); //string format date using string.format method. Console.WriteLine("as like [2013-11-30] date [yyyy-MM-dd] format: " + string.Format("{0:yyyy-MM-dd}", now)); Console.ReadLine(); } } |
Output:
1 2 3 4 5 | now: 10/23/2020 12:08:28 AM date format using TosString method: 2020-10-23 as like [2013-11-30] date [yyyy-MM-dd] format: 2020-10-23 |
Convert string date to yyyy-mm-dd format C#
How to convert string date to yyyy mm dd format in C#