查询日期
一、使用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'
/// <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;
}