最麻烦的一个写法, 累了, 脑袋进水string strBegin = "0409", strEnd = "0502"; int intYear = 2003; int intBeginMonth, intBeginDay, intEndMonth, intEndDay; intBeginMonth = Convert.ToInt32( strBegin.Substring(0, 2)); intBeginDay = Convert.ToInt32(strBegin.Substring(2)); intEndMonth = Convert.ToInt32(strEnd.Substring(0, 2)); intEndDay = Convert.ToInt32(strEnd.Substring(2)); DateTime dt1 = new DateTime(intYear, intBeginMonth, intBeginDay); DateTime dt2 = new DateTime(intYear, intEndMonth, intEndDay); string strSQL = "select * from table where birthday >= '" + dt1.ToString() + "' and birthday <= '" + dt2.ToString() + "'";
你使用的是什么数据库 如果是Access的话, 查询语句为sql = "select * from 表 where date='#2003-01-01#'"
用存储过程 create procedure sp_birthdayquery @begindate datetime, @enddate datetime as select * from table where brithday between @begindate and @enddate+1 go
int intYear = 2003;
int intBeginMonth, intBeginDay, intEndMonth, intEndDay;
intBeginMonth = Convert.ToInt32( strBegin.Substring(0, 2));
intBeginDay = Convert.ToInt32(strBegin.Substring(2));
intEndMonth = Convert.ToInt32(strEnd.Substring(0, 2));
intEndDay = Convert.ToInt32(strEnd.Substring(2));
DateTime dt1 = new DateTime(intYear, intBeginMonth, intBeginDay);
DateTime dt2 = new DateTime(intYear, intEndMonth, intEndDay);
string strSQL = "select * from table where birthday >= '" + dt1.ToString() + "' and birthday <= '" + dt2.ToString() + "'";
如果是Access的话,
查询语句为sql = "select * from 表 where date='#2003-01-01#'"
create procedure sp_birthdayquery
@begindate datetime,
@enddate datetime
as
select * from table where brithday between @begindate and @enddate+1
go