MySql DateTime with C#

Posted on 2005-04-14
Last Modified: 2008-01-09
here is my INSERT Statement:

("INSERT INTO STUDENT (FNAME,LNAME,EMAILADDRESS,DATE) VALUES ('LName','FName','','{0}')",DateTime.Now.ToShortDateString());      

using ODBC, this operation add a new record but the DateTime field is NULL...
any ideas why ?

i am using C# with MySql                   
Question by:Shay050799
    LVL 33

    Accepted Solution

    What format does ToShortDateString() return?  MySQL requires it to be in the format yyyy-mm-dd
    LVL 3

    Author Comment

    mm/dd/yyyy every DateTime object in .NET and in VC++ returns the same format
    LVL 33

    Expert Comment

    Ok, that's the problem.  You need to either turn it into yyyy-mm-dd format, or, if you have version 4.1 of MySQL, use the str_to_date function.
    LVL 3

    Author Comment

    I appreciate your help, you did point me to the right direction which is the format of the data.
    i created a small util class which convert between the 2 formats (i.e. MySQL and .NET DateTime)


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API ( …
    More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now