select orderTime = convert(varchar(10),orderTime,120) from orders 可以把时间格式的具体时间去掉,不知道对你是否有用.
假设你想得到2006-3-15 到 2006-3-20的日期你可以写(1) select * from 表名 where 日期字段 between to_date('15-3-2006 23:59:59', 'dd-mm-yyyy hh24:mi:ss') and to_date('20-3-2006 00:00:00', 'dd-mm-yyyy hh24:mi:ss') (2)把日期转换成字符串,然后截取,比较字符串还有using System; using System.Collections.Generic; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DateTime t1 = new DateTime(2006,2,2,1,1,1); DateTime t2 = new DateTime(2006,2,2,11,11,11); if (t1.Date == t2.Date) { Console.WriteLine("true"); } else { Console.WriteLine("false");
用个Conver函数,for instance: 1980 < Conver(Datetime).shortdate < 2006for detail ref: ToShortDateString()
string edate = this.Calendar2.SelectedDate.ToShortDateString();
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "select * from table1 where thedate between @startdate and @enddate";
cm.Parameters.Add("@startdate",System.Data.SqlDbType.VarChar);//用字符串类型
cm.Parameters.Add("@enddate",System.Data.SqlDbType.VarChar);//用字符串类型
cm.Parameters["@startdate"].Value = sdate;
cm.Parameters["@enddate"].Value = ddate + " 23:59:59"; System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cm);
DataTable dt = new DataTable();
da.Fill(dt);
DateTime dt2 = DateTime.Now.AddHours(3);
TimeSpan ts = dt1 - dt2;
if(ts.Days == 0)
.... if(ts.Days > 0)
....
if(ts.Days < 0)
....
orderTime = convert(varchar(10),orderTime,120)
from orders
可以把时间格式的具体时间去掉,不知道对你是否有用.
select * from 表名 where 日期字段 between to_date('15-3-2006 23:59:59', 'dd-mm-yyyy hh24:mi:ss') and to_date('20-3-2006 00:00:00', 'dd-mm-yyyy hh24:mi:ss')
(2)把日期转换成字符串,然后截取,比较字符串还有using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DateTime t1 = new DateTime(2006,2,2,1,1,1);
DateTime t2 = new DateTime(2006,2,2,11,11,11);
if (t1.Date == t2.Date)
{
Console.WriteLine("true"); }
else
{
Console.WriteLine("false");
} Console.Read(); }
}
}你可以看一下程序运行结果