| 
                
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. 
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | kshahzadStarting Member
 
 
                                        45 Posts | 
                                            
                                            |  Posted - 2013-07-17 : 11:51:26 
 |  
                                            | i have this working query below,i want to filter the record based on current date.In the query i have to hardcode the date vlaues but i want this to dynamically grab the current date.the column type is datetime.select avg(TotalUsers) from UsersLoggedIn where TimeRecorded between '2013-07-16 08:26:26.173' and '2013-07-17 17:00:30.277' |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-17 : 11:54:54 
 |  
                                          | [code]select avg(TotalUsers) from UsersLoggedIn where TimeRecorded >=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),-1) AND TimeRecorded < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  |  
                                    | kshahzadStarting Member
 
 
                                    45 Posts | 
                                        
                                          |  Posted - 2013-07-17 : 13:28:32 
 |  
                                          | what about thisTimeRecorded >=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) AND TimeRecorded < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1) |  
                                          |  |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-17 : 13:34:49 
 |  
                                          | quote:this wont start from previous date. You had start date as 16th Jul which was yesterdayThats why I started with -1------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsOriginally posted by kshahzad
 what about thisTimeRecorded >=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) AND TimeRecorded < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)
 
 |  
                                          |  |  |  
                                    | kshahzadStarting Member
 
 
                                    45 Posts | 
                                        
                                          |  Posted - 2013-07-17 : 13:37:53 
 |  
                                          | i want to collect only of current date at the end of the day like after 9 PMso i guess this would fit will in this scenario Correct?TimeRecorded >=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) AND TimeRecorded < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1) |  
                                          |  |  |  
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-07-18 : 00:45:27 
 |  
                                          | quote:Ok current day means above logic is correct------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsOriginally posted by kshahzad
 i want to collect only of current date at the end of the day like after 9 PMso i guess this would fit will in this scenario Correct?TimeRecorded >=DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0) AND TimeRecorded < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)
 
 |  
                                          |  |  |  
                                |  |  |  |  |  |