about converting datetime without time part

  • Hi All,

    I am trying to make a report with Microsoft Reporting Service.

    I have an datetime type parameter.

    In the database my field that I want to filter with time format.

    But my parameter is only date and I want to filter datas

    which field=my parameter.

    I did things as below :

    (CONVERT(nvarchar, FireBrigade_ShiftFallows.ActualStartDate, 102) = CONVERT(nvarchar, @date,102))

    but it doesn't work.What should I do?

  • Excuse my english, but i'm from Spain.

    Possible options are:

    1) If your parameter is a datetime try:

    where convert(char(10), FieldDatetime, 102) = convert(char(10), @ParamDatetime, 102)

    2) If your parameter is a string try:

    where convert(char(10), FieldDatetime, 102) = convert(char(10), convert(datetime, @ParamChar), 102)

  • Hi,

    I doesn't work.the parameter is datetime.

  • Good morning,

    Use the following:

    where cast(convert(char(10), FieldDatetime, 102) as datetime) = @ParamDatetime

    Good luck let me know if you have any more problems

    Niels Naglé

  • If you have an index over your field datetime, a better solution that uses your index can be:

    WHERE

    FieldDatetime >= CONVERT(DATETIME, CONVERT(CHAR(10), @ParamDatetime, 102))

    AND

    FieldDatetime < DATEADD(dd, 1, CONVERT(DATETIME, CONVERT(CHAR(10), @ParamDatetime, 102)))

  • many ways to skin a cat

    not that I would want to skin a real cat...

    CAST(CAST(mydate AS VARCHAR(12)) AS DATETIME)

    removes the time for comparison purposes

  • based on this:

    (CONVERT(nvarchar, FireBrigade_ShiftFallows.ActualStartDate, 102) = CONVERT(nvarchar, @date,102))

    I'd do this:

    FireBrigade_ShiftFallows.ActualStartDate >= dateadd(dd, datediff(dd, 0, @date), 0) and

    FireBrigade_ShiftFallows.ActualStartDate < dateadd(dd, datediff(dd, 0, @date) + 1, 0)

    😎

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply