• mister.magoo (2/12/2013)


    dubem1-878067 (2/12/2013)


    I have a varchar column containing dates (not my design) with this format 2013-02-12

    I need to extract records between two dates

    this code will do the job

    where convert(datetime, mydatecolumn, 120) between convert(datetime, '2012-10-10',120) and convert(datetime, '2013-04-01',120]

    but can I do simply to avoid 3 convert?

    where mydatecolumn between '2012-10-10' and '2013-04-01'

    I would say yes.

    you will end up comparing three char based strings which, because of the reverse notation yyyy-mm-dd will compare quite nicely.

    There is no need to convert to dates at all - or am I missing something here?

    I was thinking the same thing. Might even be able to use an index.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.