How to parse date value from a string in C#

4 Answers

0 votes
using System;

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

            DateTime dt = DateTime.Parse(s);

            Console.WriteLine(dt);
        }
    }
}

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

*/

 



answered Jan 18, 2017 by avibootz
0 votes
using System;

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

            DateTime dt = DateTime.Parse(s);

            Console.WriteLine(dt);
        }
    }
}

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

*/

 



answered Jan 18, 2017 by avibootz
0 votes
using System;

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

            DateTime dt = DateTime.Parse(s);

            Console.WriteLine(dt);
        }
    }
}

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

*/

 



answered Jan 18, 2017 by avibootz
0 votes
using System;

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

            DateTime dt = DateTime.Parse(s);

            Console.WriteLine(dt);
        }
    }
}

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

*/

 



answered Jan 18, 2017 by avibootz

Related questions

1 answer 165 views
2 answers 182 views
1 answer 165 views
1 answer 156 views
156 views asked Sep 7, 2019 by avibootz
1 answer 146 views
146 views asked Jan 18, 2017 by avibootz
...