/// <summary> /// 按日期查询 /// </summary> private string QueryByDate() { string date1 = this.inquirePage.dateTimePicker1.SelectedDate?.ToString("yyyy-M-dd HH:mm:ss"); DateTime temp1; DateTime temp2; string date2 = string.Empty; if (this.inquirePage.dateTimePicker2.SelectedDate != null) { temp1 = this.inquirePage.dateTimePicker2.SelectedDate.Value; temp2 = new DateTime(temp1.Date.Year, temp1.Date.Month, temp1.Date.Day, 23, 59, 59); date2 = temp2.ToString("yyyy-M-dd HH:mm:ss"); } if (date1 == null || date2.Equals(string.Empty)) { MessageBox.Show("时间格式错误!"); return string.Empty; } string sql = "select * from BatchNumberInfo where Start_Time > '" + date1 + "' and End_Time < '" + date2 + " '"; return sql; }

查询日期
一、使用Between AND
select * from BatchNumberInfo where Start_Time Between '2019-1-01 00:00:00' AND '2019-7-12 23:59:59'
二、使用>,<
select * from BatchNumberInfo where Start_Time > '2019-1-01 00:00:00' and Start_Time < '2019-12-12 23:59:59'
注意:sqllite的datetime字符串形式第一个是"yyyy-M-dd HH:mm:ss",第二个是'yyyy-M-dd hh:mm:ss'
————————————————
版权声明:本文为CSDN博主「物随心转」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sinat_31608641/article/details/104561679