Home > DeveloperSection > Forums > C# DateTime MySQL Command
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    December-12-2013 1:49 AM

 C# C# 
Ratings:


 1 Reply(s)
 1664  View(s)
Rate this:

I am having issues with using the DateTime as the parameter to work for a sql query.

Here is the query I would like :

command.CommandText = "SELECT idGameNumber FROM GameOutcome WHERE GameOutcome.gameDate = <insert DateTime game_time>";

where game_time is a DateTime object and Gameoutcome.gameDate is a DATETIME datatype.

What do I need to put on the right side of the = sign in there WHERE clause?



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-12-2013 2:22 AM

Hi jayPrakash,

using DateTime string

MYSQL takes the DateTime in Following default format:

yyyy-MM-dd HH:mm:ss

so you can convert your datetime object into above format.

Try This:

command.CommandText ="SELECT idGameNumber FROM GameOutcome WHERE GameOutcome.gameDate ='"+ game_time.ToString("yyyy-MM-dd HH:mm:ss")+"'";


Don't want to miss updates? Please click the below button!

Follow MindStick