EasyCFM.COM ColdFusion Forums / Coding Help! / Blanking a Date field

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Blanking a Date field

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

StoneRose
03-22-2010 @ 9:48 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 80
Joined: Dec 2008

Lets say there's a situation where you've set a date in a date/time DB field and now the date no longer applies and you want to blank out the field on an update.

It says datatype mismatch when try to update with an empty string (ha.. can I dateformat an empty string?)

Webmaster
03-22-2010 @ 10:06 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4533
Joined: Jan 2002

you will have to NULL it.

update table set datefield = null where id = 566

HTH

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---

StoneRose
03-26-2010 @ 7:28 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 80
Joined: Dec 2008

Wow... too easy but only found here, couldn't find it on Google. Thank you.

StoneRose
03-29-2010 @ 11:51 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 80
Joined: Dec 2008

Ok, then why doesn't
<cfif thedate is NULL> work?

Lyndon
03-31-2010 @ 2:20 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 66
Joined: Jun 2004

Try <cfif Not IsDate(thedate)>...<cfif>

Lyndon

This message was edited by Lyndon on 3-31-10 @ 2:20 PM

cfSearchin
03-31-2010 @ 5:15 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 608
Joined: Feb 2008

quote:

Ok, then why doesn't
<cfif thedate is NULL> work?


Because ColdFusion does not really have the concept of NULL values. In cfquery results, any NULL values are essentially converted to an empty string ie "".  So your cfif conditions should test accordingly. As mentioned, you can also use functions like IsDate(), IsNumeric(), etecetera if it is more appropriate for the given value.

This message was edited by cfSearchin on 3-31-10 @ 6:07 PM

Webmaster
03-31-2010 @ 5:36 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4533
Joined: Jan 2002

You could also do:

<cfif NOT len(trim(thedate))>

That looks for the value to not be blank.

P

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

\m/ (>.<) \m/
--- rock on ---

Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.