How to convert Datetime in the format dd/MM/yyyy using Convert.ToDatetime in C

Posted on 2009-04-28
Last Modified: 2013-12-17
I have a string in the format dd/MM/yyyy and i am doing Convert.ToDateTime in C#.Net to convert it to DateTime and i am getting the error "threw an exception of type 'System.FormatException'      System.DateTime {System.FormatException}

Can anyone please help.
Question by:MPakeezah
    LVL 22

    Accepted Solution

    it might be better to try DateTime.Parse or TryParse
    LVL 1

    Assisted Solution

    Do you have the code?
    It is easier to help if I could see what you did that threw that error
    LVL 14

    Assisted Solution


    Use like this.

            DateTimeFormatInfo finfo = new DateTimeFormatInfo();
            finfo.ShortDatePattern = "dd/MM/yyyy";
            Convert.ToDateTime("31/01/2009", finfo);
    LVL 26

    Assisted Solution

    by:Anurag Thakur
    use datetime.tryparse

    also pass in the culture en-GB beacuse you are using dd/MM/yyyy and by default the culture will be MM/dd/yyyy and if you use date as 12/12/2009 it will be ok in both cases and if you use date as 31/12/2009 then casting will give error in en-US (default culture) and will work ok in en-GB culture

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    IIs block files web.config 6 45
    C# primary key 9 46
    How to perform calculation 2 19
    varchar (max) 5 21
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now