Iif/datediff

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • green51
    New Member
    • Jun 2007
    • 18

    #1

    Iif/datediff

    hi
    In the below command I like to know can I combine it with the IIf function.
    I am checking to see if NSCHD is blank. If it is blank I would place "no date"
    in the place of the result..
    "Starts In " & DateDiff("d",Fo rmat(Date(),"mm/dd"),Format([NSCHD],"mm/dd")) & " Days"


    Thanks
    bg
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi
    Originally posted by green51
    hi
    In the below command I like to know can I combine it with the IIf function.
    I am checking to see if NSCHD is blank. If it is blank I would place "no date"
    in the place of the result..
    "Starts In " & DateDiff("d",Fo rmat(Date(),"mm/dd"),Format([NSCHD],"mm/dd")) & " Days"


    Thanks
    bg
    You don't say where you are using this but I thing this would be better, it may even work!

    "Starts In " & DateDiff("d",Da te(),[NSCHD]) & " Days"

    Why format it as you actualy state "Starts in xx Days" and the fuction is set to return days ??

    Note days will not format as mm/dd correctly (I believe).

    MTB

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      I'd use a simple If...Then construct rather than IIF simply because it's easier to tell at a glance what's going on, and using expressions within IFF can get complicated with hard to spot errors resulting . Also, there's no need to use formatting on your dates in the DateDiff function; you're returning a number of days, not a date. I'd do something like this:

      [CODE=vb]If IsNull(NSCHD) Then
      "No Date"
      Else
      "Starts In " & DateDiff("d",Da te,NSCHD) & " Day(s)"
      End If
      [/CODE]

      Good Luck!

      Linq ;0)>

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        Originally posted by green51
        hi
        In the below command I like to know can I combine it with the IIf function.
        I am checking to see if NSCHD is blank. If it is blank I would place "no date"
        in the place of the result..
        "Starts In " & DateDiff("d",Fo rmat(Date(),"mm/dd"),Format([NSCHD],"mm/dd")) & " Days"


        Thanks
        bg

        Yha, you can use it like

        Code:
        "Starts In " & iif(DateDiff("d",Date,NSCHD) = 0,"No",DateDiff("d",Date,NSCHD)) & " Days"

        but if Mike's qurey is workink then you can use that,

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Didn't mean to step on your toes, Mike! Had to take the dog out between starting and ending my response. Actually the DateDiff will run with the dates formatted, it's just not necessary!

          ;0)>

          Comment

          • MikeTheBike
            Recognized Expert Contributor
            • Jun 2007
            • 640

            #6
            Hi missinglinq
            Originally posted by missinglinq
            Didn't mean to step on your toes, Mike! Had to take the dog out between starting and ending my response. Actually the DateDiff will run with the dates formatted, it's just not necessary!

            ;0)>
            That is not a problem, anything can happen between staring a post and submitting it, and offen does!

            I have never tried formatting a date inside DateDiff, had no reason to (yet!), but I will take your word for it.

            MTB

            Comment

            Working...