• Matt Miller (7/7/2008)


    Giya (7/7/2008)


    The user is choosing the date range from calendar control and it displays in mm/dd/yyyy format as 06/01/2008. Is there any way around?

    If you pass this stuff back as dates and not as character fields, you wouldn't be running into string comparisons. I'm not sure why noone wants to do this, but even if you have to pass your date params as strings, convert them back to dates before using.

    as in :

    ....

    where effdate >=cast(@startdate as datetime) and effdate<cast(@enddate as datetime)

    ....

    And of course, if you do it this way and there is an index on effdate the index could be used. If you use the previously posted methods - the index cannot be used.

    If you are worried about the time, then just strip the time - as in:

    where effdate >= dateadd(day, datediff(day, 0, @startdate), 0)

    and effdate < dateadd(day, 1, dateadd(day, datediff(day, 0, @enddate), 0)

    If the column effdate is a datetime column - @startdate and @enddate in the above will be implicitly converted to a datetime data type to match the column.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs