Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9522
  • Last Modified:

MySql DateTime with C#

here is my INSERT Statement:

("INSERT INTO STUDENT (FNAME,LNAME,EMAILADDRESS,DATE) VALUES ('LName','FName','email@server.com','{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                   
0
Shay050799
Asked:
Shay050799
  • 2
  • 2
1 Solution
 
snoyes_jwCommented:
What format does ToShortDateString() return?  MySQL requires it to be in the format yyyy-mm-dd
0
 
Shay050799Author Commented:
mm/dd/yyyy every DateTime object in .NET and in VC++ returns the same format
0
 
snoyes_jwCommented:
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.
http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html
0
 
Shay050799Author Commented:
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)

thanks
Shay
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now