Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 8th, 2006, 03:15 PM
Authorized User
 
Join Date: Jan 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default .NET and MySQL DateTimes in C#

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";

 
Old December 2nd, 2006, 12:37 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You have to add single quotes ' aound the date

 
Old December 14th, 2006, 05:52 AM
Skb Skb is offline
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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))

 
Old December 14th, 2006, 01:12 PM
Authorized User
 
Join Date: Jan 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What does the '112' represent?

 
Old December 15th, 2006, 01:12 AM
Skb Skb is offline
Authorized User
 
Join Date: Oct 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

112 is one of the output format.
refer the link for more details.

http://msdn2.microsoft.com/en-us/library/ms187928.aspx

 
Old December 15th, 2006, 12:00 PM
Authorized User
 
Join Date: Jan 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. That is exactly what I needed! :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
MySql with .Net aliirfan84 MySQL 2 April 11th, 2007 03:05 AM
c# connection string for .Net 1.1 with Mysql srkarthik_82 General .NET 0 January 17th, 2007 06:58 AM
ASP.Net 2.0 with MySQL burdickdave ASP.NET 2.0 Professional 2 March 3rd, 2006 08:10 PM
MySQL 5 with ASP.Net 2.0 burdickdave MySQL 1 February 22nd, 2006 08:37 PM
vb.net and mysql pascalgeuze VB.NET 1 January 21st, 2005 07:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.