Conditional Formatting of Date Parameter

  • Hey guys,

    I have a report that returns data based on 2 date parameters, using the WHERE BETWEEN query. It works fine, except for the fact that I don't want the user to be able to specify the first date as a later date than the second date.

    For example, I don't want the user to be able to search using "1/1/2012" as the first date and "1/1/1950" as the second. Obviously, the first date should always be prior to the second. How do I make it so that this returns an error if the user tries to do this?

    Thanks!

  • Use the DATEDIFF function - check it out on Books On Line (BOL) or read this:

    http://msdn.microsoft.com/en-us/library/ms186724.aspx#GetDateandTimeDifference

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • bitbucket-25253 (7/2/2012)


    Use the DATEDIFF function - check it out on Books On Line (BOL) or read this:

    http://msdn.microsoft.com/en-us/library/ms186724.aspx#GetDateandTimeDifference

    Thank you BitBucket. Sorry for sounding novice, but I assume you mean use a boolean expression to determine if the date difference is negative? If so, what code should I put in the code to return an error? Is my code below in the ball park?

    =IIF(DATEDIFF(DateInterval.Second,Paramaters!Date2.Value,Parameters!Date1.Value)>0,NOTHING,Code.DisplayMessage("From Date must be before To Date. Please try again."))

    Thank you again.

  • I would use something like this

    DECLARE @T1 DATETIME

    DECLARE @T2 DATETIME

    SET @T1 = '7/02/2012' | The 2 parameters passed to your T-SQL statement

    SET @T2 = '7/03/2012' |

    -----------------------------

    IF DATEDIFF(DD,@T1,@T2) <=0

    BEGIN

    PRINT 'set return value here'

    RETURN

    END

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

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