How to try parse date value from a string in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "2017-01-18";

            DateTime dt;
            if (DateTime.TryParse(s, out dt))
            {
                Console.WriteLine(dt);
            }

            s = "2017-01-40";
            if (DateTime.TryParse(s, out dt))
            {
                Console.WriteLine(dt);
            }
        }
    }
}

/*
run:
   
18/01/2017 00:00:00

*/

 



answered Jan 18, 2017 by avibootz

Related questions

1 answer 125 views
1 answer 157 views
1 answer 148 views
1 answer 161 views
2 answers 182 views
4 answers 223 views
223 views asked Jan 18, 2017 by avibootz
...