Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfif database issue

Guest
Oct 23, 2008 Oct 23, 2008
Any idea why my code is excuting even though my database column lunch_out_time is blank/null?

<cfif getpeople.lunch_out_time NEQ "">
<cfset time2 = TimeFormat(getpeople.lunch_out_time, "hh:mm")>
<cfset time3 = DateAdd("h", 1, time2)>
<cfset time4 = DateAdd("n", 15, time3)>
<cfset time5 = Timeformat(time4, "hh:mm")>
<cfset time55 = Now()>
<cfset time555 = DateAdd("h", 1, time55)>
<cfset time6 = Timeformat(time555, "hh:mm")>
<cfif time5 LTE time6 AND getpeople.emailed EQ 2>
616
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 23, 2008 Oct 23, 2008
I'm not sure, but be aware that there could be hidden characters in there such as a space. The next best step to take is to be a bit more strict with your checking and validation. Try the following code and see what you get:

<cfif trim(getpeople.lunch_out_time) NEQ "" AND len(trim(getpeople.lunch_out_time)) GT 0>
<cfset time2 = TimeFormat(getpeople.lunch_out_time, "hh:mm")>
<cfset time3 = DateAdd("h", 1, time2)>
<cfset time4 = DateAdd("n", 15, time3)>
<cfset time5 = Timeformat(time4, "hh:mm")>
<cfset time55 = Now()>
<cfset time555 = DateAdd("h", 1, time55)>
<cfset time6 = Timeformat(time555, "hh:mm")>
<cfif time5 LTE time6 AND getpeople.emailed EQ 2>

A combination of TRIM and LEN functions on your variable might do the trick. Trim, trims the text and len will check the length of the string.

Also be aware that NULL is different from BLANK. Blank could have a value such as a space or other hidden character, where as NULL is no value at all - nothing. These are very different from each other.

Good luck,
Mikey.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2008 Oct 23, 2008
When I am confronted with these types of problems, my approach is:
if somevariable is or is not some expected value
code
cfelse
look at the variable. In your case, it would be
<cfump var="a#getpeople.lunch_out_time#b">

If you get anything between the a and b, including whitespace, you'll know why your code didn't perform as expected.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 23, 2008 Oct 23, 2008
PopcornCoder wrote:
> Any idea why my code is excuting even though my database column lunch_out_time is blank/null?

What is the data type of lunch_out_time? If it contains a time, it should not be stored as varchar.

> <cfset time2 = TimeFormat(getpeople.lunch_out_time, "hh:mm")>

I think this was already mentioned in another thread, but TimeFormat returns a string not a date time object. It is typically used for display purposes, after any date calculations are performed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 24, 2008 Oct 24, 2008
LATEST
I know it's already been mentioned, but you might want to try:
<cfif not len(lgetpeople.lunch_out_time)>

I just ran into this yesterday, I wanted to do something if a date field was blank. NEQ will not work if it's a date / time field.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources