Skip to main content
January 31, 2009
Answered

cfif not working

  • January 31, 2009
  • 7 replies
  • 874 views
I'm can't figure out why this isn't working. If I remove the if block it works. Otherwise, it doesn't.
This topic has been closed for replies.
Correct answer
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 replies

Inspiring
February 2, 2009
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/
Correct answer
February 2, 2009
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.
Inspiring
February 2, 2009
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/
February 2, 2009
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.
February 1, 2009
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...
Inspiring
January 31, 2009
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.
Inspiring
January 31, 2009
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/
Known Participant
January 31, 2009
Since you mention it Azadi, is

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

bad or just excessive compared to

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

Inspiring
January 31, 2009
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/