Calendar Control + MSAccess

  • Thread starter Thread starter T
  • Start date Start date
T

T

Hi,

I'm using the Calendar Control in an C# SWF application.
I have a field in an Access Table which is of the Date/Time type.

In access the dates are stored with a time index aswell, but I don't need to
care about those.

So lets say I have this in the table

11-02-2003 11:36:21
02-05-2003 12:45:01

And I select 02-05-2003 in the Calendar control
I want to select all fields from that table in access where the data is
02-05-2003 without
looking at the timeindex. At the moment I never get any fields as it always
looks at the timeindex aswell.

What select query should I use to ignore the time and only compare dates ?

SELECT * FROM PERIOD WHERE STARTDATE = .........


Thnx
 
¤ Hi,
¤
¤ I'm using the Calendar Control in an C# SWF application.
¤ I have a field in an Access Table which is of the Date/Time type.
¤
¤ In access the dates are stored with a time index aswell, but I don't need to
¤ care about those.
¤
¤ So lets say I have this in the table
¤
¤ 11-02-2003 11:36:21
¤ 02-05-2003 12:45:01
¤
¤ And I select 02-05-2003 in the Calendar control
¤ I want to select all fields from that table in access where the data is
¤ 02-05-2003 without
¤ looking at the timeindex. At the moment I never get any fields as it always
¤ looks at the timeindex aswell.
¤
¤ What select query should I use to ignore the time and only compare dates ?
¤
¤ SELECT * FROM PERIOD WHERE STARTDATE = .........
¤

What does the criteria in your SQL statement look like?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Include two DateTime values for the earliest and latest that you want and
select based on both on the where clause. I'm not sure on the exaxt syntax,
but here is some pseudo code (untested)....

DateTime dtAM = <your date at 12am>
DateTime dtPM = <next day at 12am>
SqlParameter cmdSel = ...;
cmdSel.CommandText = "SELECT * FROM PERIOD WHERE Datum > @DateAM AND Datum <
@DatePM"
SqlParameter prmAM = cmdSel.Parameters.Add("@DateAM");
prmAM.SourceColumn = "Datum";
prmAM.Value = dtAM;
SqlParameter prmPM = cmdSel.Parameters.Add("@DatePM");
prmPM.SourceColumn = "Datum";
prmPM.Value = dtPM;

I have not tested this. I'm not sure if you can have 2 parameters with the
same source column? The help files don't say one way or the other.

Another option may be calling a SQL method that does something similar, or a
stored procedure that does the same?
 
Thnx,

I can use between with your idea

Michael Lang said:
Include two DateTime values for the earliest and latest that you want and
select based on both on the where clause. I'm not sure on the exaxt syntax,
but here is some pseudo code (untested)....

DateTime dtAM = <your date at 12am>
DateTime dtPM = <next day at 12am>
SqlParameter cmdSel = ...;
cmdSel.CommandText = "SELECT * FROM PERIOD WHERE Datum > @DateAM AND Datum <
@DatePM"
SqlParameter prmAM = cmdSel.Parameters.Add("@DateAM");
prmAM.SourceColumn = "Datum";
prmAM.Value = dtAM;
SqlParameter prmPM = cmdSel.Parameters.Add("@DatePM");
prmPM.SourceColumn = "Datum";
prmPM.Value = dtPM;

I have not tested this. I'm not sure if you can have 2 parameters with the
same source column? The help files don't say one way or the other.

Another option may be calling a SQL method that does something similar, or a
stored procedure that does the same?

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/dbobjecter (code generator)
http://sourceforge.net/projects/genadonet ("generic" ADO.NET)
 
Back
Top