locked
Get Number Of Data to this Day RRS feed

  • Question

  • How I get the Book enter By the Current User to this Day

    DateEnter    smallDateTime
    
    select COUNT(ID) from BookInfo where DateEnter=CONVERT (date, GetDate(),3)
    
    he return  0  value 

     

     

    Friday, February 18, 2011 6:58 AM

Answers

All replies

  • select COUNT(ID) from BookInfo where CONVERT (date, DateEnter,1) =CONVERT (date, GetDate(),1)

    Try this............!
    
    
    • Proposed as answer by Civic1986 Friday, February 18, 2011 7:02 AM
    • Marked as answer by KhaLeeL ZoURoB Friday, February 18, 2011 8:57 PM
    • Unmarked as answer by Kalman Toth Saturday, February 19, 2011 12:05 AM
    Friday, February 18, 2011 7:02 AM
  • Hi,

    What is the value in your dateenter column

    i tried running the query and i got the correct results

     

    declare @t table(id int,dateenter date)
    insert into @t
    select 1,'2011-02-18'
    union all
    select 2,'2011-02-18'


    select COUNT(Id) from @t where dateenter=CONVERT(date,GETDATE())


    Thanks and regards, Rishabh
    Friday, February 18, 2011 7:16 AM
  • Try

    select count(ID) from BookInfo where DateEnter >=dateadd(day,datediff(day,'19000101',getdate()),'19000101') and 
    
    DateEnter < dateadd(day,datediff(day,'19000101',getdate()),'19000102') -- next date
    

    Read the following links explaining how to work with dates

    The ultimate guide to the datetime datatypes

    Bad habits to kick : mis-handling date / range queries

    You should not use any functions on the DateEnter field if you want to be able to utilize an index (if you have it). You may want to take a look at this blog post as well

    Only In A Database Can You Get 1000% + Improvement By Changing A Few Lines Of Code


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by Kalman Toth Saturday, February 19, 2011 12:05 AM
    Friday, February 18, 2011 7:09 PM
  • thanks  you  very much
    Friday, February 18, 2011 9:00 PM
  • I unmarked the following query because the WHERE predicate is not sargable.

    select COUNT(ID) from BookInfo

    where CONVERT (date, DateEnter,1) =CONVERT (date, GetDate(),1)


    Kalman Toth, Admin/Prog, SSAS, SSIS, SSRS; SQL 2008 GRAND SLAM
    Saturday, February 19, 2011 12:06 AM