10 Replies Latest reply on Feb 2, 2009 1:46 AM by

    cfif not working

      I'm can't figure out why this isn't working. If I remove the if block it works. Otherwise, it doesn't.
        • 1. Re: cfif not working
          Level 7
          1) define "not working", please. post any errors thrown by cf.
          2) what is the value of #date# variable and where is it coming from?
          3) easy on the " and # - you have way more of both of them than needed!

          that's for starters...

          Azadi Saryev
          Sabai-dee.com
          http://www.sabai-dee.com/
          1 person found this helpful
          • 2. Re: cfif not working
            Mi-ul-vmijiI Level 1
            Since you mention it Azadi, is

            DateDiff("d", "#date#", "#now()#")

            bad or just excessive compared to

            DateDiff("d", date, now())

            1 person found this helpful
            • 3. Re: cfif not working
              Level 7
              it is usually just excessive - adds unnecessary processing.
              it can be plain bad sometimes, too.
              in this case, i'd say it depends on what the value of #date# is - a date
              object or a text string...


              Azadi Saryev
              Sabai-dee.com
              http://www.sabai-dee.com/
              • 4. Re: cfif not working
                Dan Bracuk Level 5
                now() returns the current date and time down to less than a second. Depending on what your date variable is, it will either never be the same as now(), or will only do so very briefly.
                • 5. Re: cfif not working
                  OK. Sorry about that. It isn't throwing any errors. It just isn't updating like it should. Here is the example: http://tinyurl.com/dedtwv

                  There are #all.RecordCount# tips in total! This is tip #AllDayRandom#... The current time is #now()# The stored date is #date# <br>
                  The date difference is #Abs(DateDiff("d", "#date#", "#now()#"))#
                  This is just tracking so I can see what is going on.

                  What is supposed to happen is this. The application has 2 tables. 1 of the tables is a single row with 2 columns. date and random_number. It's set up so there is no primary key because basically I'm using it as a variable that gets overwritten. Now what happens is when you visit the page, it is supposed to do a check against the current date and the date stored in the table. If the difference is 1 or more, i.e. it's not today, the query updates the table with the current date and sets a new random number. Then runs the query and displays the new tip of the day based on that new random number. Otherwise it runs through the else block. i.e. it is the same day.

                  Now, if I remove the if block, it works fine. However, inside of the if block it doesn't work, it just goes right to the cfelse part.

                  Hope that's clear...
                  • 6. Re: cfif not working
                    DaveH225
                    I'm completely new to CF, so I may be stating the obvious or be completely off mark here, but shouldn't NEQ "0" be NEQ 0. You're comparing to a string. I know that CF handles data types different to what I'm used to, but that's one thing that jumps out at me.
                    • 7. Re: cfif not working
                      Level 7
                      what is the exact value of your #date# variable? is it a date object or
                      a date as text string?

                      Azadi Saryev
                      Sabai-dee.com
                      http://www.sabai-dee.com/
                      • 8. cfif not working
                        quote:

                        Originally posted by: DaveH225
                        I'm completely new to CF, so I may be stating the obvious or be completely off mark here, but shouldn't NEQ "0" be NEQ 0. You're comparing to a string. I know that CF handles data types different to what I'm used to, but that's one thing that jumps out at me.

                        You my friend are a freaking genius. You know, nobody caught that but you. I thank you. It works beautifully now.

                        quote:

                        Originally posted by: Newsgroup User
                        what is the exact value of your #date# variable? is it a date object or
                        a date as text string?

                        Azadi Saryev
                        Sabai-dee.com
                        </blockquote>"> http://www.sabai-dee.com/.[/q[/Q
                        [/L]
                        It's a date. I use #CreateODBCDate(now())# to make it and it's a date field in MySQL. Dave solved the problem for me though. It works now.
                        • 9. Re: cfif not working
                          Level 7
                          if it is a date then do not enclose it in " (quotes) when passing it to
                          DateDiff() function

                          Azadi Saryev
                          Sabai-dee.com
                          http://www.sabai-dee.com/
                          1 person found this helpful
                          • 10. Re: cfif not working
                            quote:

                            Originally posted by: Newsgroup User
                            if it is a date then do not enclose it in " (quotes) when passing it to
                            DateDiff() function

                            Azadi Saryev
                            Sabai-dee.com
                            http://www.sabai-dee.com/



                            Ya, I need to refresh myself on what needs in quotes and what does not.