i have an table with column as timestamp value gets stored like this "2010-12-18 16:36:26.363"
the table name is employee
As records get inserted with time value i am not able to find the records inseted for today date.
Is there any way i can write an Query to find teh REcords inseted for a particuar day. sothat i can get all the records inseted for that day
any 开发者_JAVA百科help would be great.
thanks
You can try
SELECT *
FROM <YourTable>
WHERE DATEADD(dd,0, DATEDIFF(dd,0,<TimeStampColum>)) = '01 Jan 2010'
Or maybe something like
SELECT *
FROM <YourTable>
WHERE DATEADD(dd,0, DATEDIFF(dd,0,<TimeStampColum>)) = DATEADD(dd,0, DATEDIFF(dd,0,GETDATE()))
This calculation DATEADD(dd,0, DATEDIFF(dd,0,<TimeStampColum>))
will return the Date
part only of a DateTime
value
You can use this script.
@ProccessDay datetime = '2010-12-20'
@ProccessTimeMin datetime,
@ProccessTimeMax datetime,
Set @ProccessTimeMin= DATEADD(s,+1,DATEADD(day , -1, @ProccessDay ))
Set @ProccessTimeMax= DATEADD(s,-1,DATEADD(day , +1, @ProccessDay ))
BEGIN
select * from table where TimeStamp between @ProccessTimeMin and @ProccessTimeMax
精彩评论