SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create a View to Just Get Today's Data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

iahii_2005
Starting Member

4 Posts

Posted - 09/02/2008 :  10:55:55  Show Profile  Reply with Quote
Hi,
Guys i am really new to SQL Server.Here is my problem i am trying to create a view to get just today's data from a table that has a 'tEndtime' Column that has the value in this format for example:7/29/2008 5:31:21 PM ; Is there a way to just extract just the date from the 'tEndtime' Column and to use a where clause to just dispaly today's data...whatever today is.Thanks

SwePeso
Patron Saint of Lost Yaks

Sweden
30240 Posts

Posted - 09/02/2008 :  10:58:52  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Assuming tEndTime is DATETIME or SMALLDATETIME, try this
SELECT	*
FROM	Table1
WHERE	tEndtime >= DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '19000101')
	AND tEndtime < DATEADD(DAY, DATEDIFF(DAY, '18991231', GETDATE()), '19000101')



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

iahii_2005
Starting Member

4 Posts

Posted - 09/02/2008 :  11:10:01  Show Profile  Reply with Quote
Wow! that works...can you please briefly explain how this functions?...
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22755 Posts

Posted - 09/02/2008 :  11:12:57  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
See what this returns

SELECT
tEndtime = DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '19000101'),
tEndtime = DATEADD(DAY, DATEDIFF(DAY, '18991231', GETDATE()), '19000101')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

iahii_2005
Starting Member

4 Posts

Posted - 09/05/2008 :  10:19:51  Show Profile  Reply with Quote
Hi,
It relation to above post how would i just display the data from 07:00AM to 23:30PM..so basically further filtering?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30240 Posts

Posted - 09/05/2008 :  10:27:36  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Same thing.
SELECT	*
FROM	Table1
WHERE	tEndtime >= DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '19000101 07:00')
	AND tEndtime < DATEADD(DAY, DATEDIFF(DAY, '19000101', GETDATE()), '19000101 23:30')



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000