Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    3

    Cool Unanswered: truncate time from datetime field

    I know that we can use convert function to remove time part from datetime. However, if I make any criteria such as

    select *
    from atable
    where convert(...,timefield,....) = '01-jan-2003'

    it cannot utilise the index on the 'timefield' since the field is converted. Do anyone know there is any way around to convert datetime and can make sql server to utilise the date index as well. thx

  2. #2
    Join Date
    Dec 2003
    Posts
    31

    try this

    select *
    from atable
    where convert(...,timefield,....) = '01-jan-2003'

    declare @startdate datetime , @enddate datetime
    select @startdate = '01-jan-2003'
    select @enddate= dateadd(dd, 1, @startdate)
    select *
    from atable
    where timefield >= @startdate and date_scored< @enddate

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •