Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Filter DateTime

Author  Topic 

ravininave
Posting Yak Master

111 Posts

Posted - 2010-06-24 : 13:52:17
Hi, in my application I've Date like
2010-06-11 11:54:32.683
I've to find DateTime Before 12:00 O'Clock and DateTime After 12:00 Means

2010-06-11 11:54:32.683
Will return 1st Shift
2010-06-11 12:20:32.500
Will return 2nd Shift


VB6/ASP.NET
------------------------
http://www.nehasoftec.com

jorge_martin_hn
Starting Member

2 Posts

Posted - 2010-06-24 : 14:35:36
You can use in the
where
date between '2010-06-11' , '2010-0611 23:59:59'
thats filter all of the day 11
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-24 : 14:35:43
Would that be Noon?

Look up DATEDIFF in BOL

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-06-24 : 15:32:18
quote:
Originally posted by jorge_martin_hn

You can use in the
where
date between '2010-06-11' , '2010-0611 23:59:59'
thats filter all of the day 11

You want to be careful when using BETWEEN and dates with times:
DECLARE @Foo TABLE (date DATETIME)

INSERT @Foo
SELECT '2010-06-11 23:59:59.995'

SELECT *
FROM @Foo
where date between '2010-06-11' AND '2010-06-11 23:59:59'

-- Better
SELECT *
FROM @Foo
WHERE
Date >= '2010-06-11'
AND DATE < '2010-6-12'
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-24 : 17:03:08
quote:
Originally posted by ravininave

Hi, in my application I've Date like
2010-06-11 11:54:32.683
I've to find DateTime Before 12:00 O'Clock and DateTime After 12:00 Means

2010-06-11 11:54:32.683
Will return 1st Shift
2010-06-11 12:20:32.500
Will return 2nd Shift


VB6/ASP.NET
------------------------
http://www.nehasoftec.com


Please be more clear what you want to do.
select a shift from a table or what?



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ravininave
Posting Yak Master

111 Posts

Posted - 2010-06-25 : 00:34:09
quote:
Originally posted by Lamprey

quote:
Originally posted by jorge_martin_hn

You can use in the
where
date between '2010-06-11' , '2010-0611 23:59:59'
thats filter all of the day 11

You want to be careful when using BETWEEN and dates with times:
DECLARE @Foo TABLE (date DATETIME)

INSERT @Foo
SELECT '2010-06-11 23:59:59.995'

SELECT *
FROM @Foo
where date between '2010-06-11' AND '2010-06-11 23:59:59'

-- Better
SELECT *
FROM @Foo
WHERE
Date >= '2010-06-11'
AND DATE < '2010-6-12'




Very True
I haven't use between. Actually I've to find shift so I'd written
Date >= '2010-06-11'
and Date <= '2010-06-11 11:59:59' FOR FIRST SHIFT
FOR SECOND
Date >= '2010-06-11 12:00:00'
and Date <= '2010-06-11 23:59:59'

THANX


VB6/ASP.NET
------------------------
http://www.nehasoftec.com
Go to Top of Page
   

- Advertisement -