|
Subject:
|
.NET and MySQL DateTimes in C#
|
|
Posted By:
|
Ric_H
|
Post Date:
|
11/8/2006 2:15:49 PM
|
I am working in Visual Studeo on an aspx.cs page. I have a datagrid that retrieves information from a MySQL DB. I am having problems with the DateTime in the Select statement. I am trying to compare two dates with either the < or the > operators. I have a DateTime variable that loads the date I want. The error that I am getting is that the DateTime variable automatically adds the time 12:00 AM to the end of the date I specify as date1. My Select statement reads the 12:00 AM and doesn't recognize it and throws an error. In C# how can I get around this error? Any ideas?
DateTime date1 = new DateTime(2006, 10, 4);
string strFOSFull = "SELECT contest, payment_type, cc_amount, payment_dttm FROM footballd.fb06_payment"; strFOSFull += " WHERE contest = 'FBFULL2006' OR contest = 'FBMID2006' AND "; strFOSFull += "payment_type = 'FOSDOLLARS' AND payment_dttm < "; strFOSFull += date1; strFOSFull += " ORDER BY payment_dttm";
|
|
Reply By:
|
jbenson001
|
Reply Date:
|
12/1/2006 11:37:18 PM
|
You have to add single quotes ' aound the date
|
|
Reply By:
|
Skb
|
Reply Date:
|
12/14/2006 4:52:13 AM
|
U can convert both the dates into same format and compare, like
select ........ from ....... where convert(datetime,convert(varchar,payment_dttm,112)) < convert(datetime,convert(varchar,'" + date1 + "',112))
|
|
Reply By:
|
Ric_H
|
Reply Date:
|
12/14/2006 12:12:13 PM
|
What does the '112' represent?
|
|
Reply By:
|
Skb
|
Reply Date:
|
12/15/2006 12:12:36 AM
|
112 is one of the output format. refer the link for more details.
http://msdn2.microsoft.com/en-us/library/ms187928.aspx
|
|
Reply By:
|
Ric_H
|
Reply Date:
|
12/15/2006 11:00:03 AM
|
Thanks. That is exactly what I needed! 
|