IsDate() and SQL Server

I don't know about you, but my company uses the IsDate() function for a lot of simple validation of date inputs, and it works fairly well for the most part. The only problem I have with it is that when paired with SQL Server (2000 or 2005), it still can't capture all invalid dates.

The date 'January 5, 753' is a valid date, but attempting to insert it into a SQL Server datetime object throws an error because valid dates for SQL Server are between January 1, 1753 and December 31, 9999. Dates above the year 9999 are caught by IsDate(), but the lower bound is not.


<cffunction name="IsSQLServerDate" returntype="boolean" output="false">
    <cfargument name="date" type="date" required="true"/>
    <cfargument name="type" type="string" required="false" default="datetime"/>

    <cfswitch expression="#arguments.type#">
        <cfcase value="datetime">
            <cfreturn IsDate(arguments.date) AND Year(arguments.date) gte 1753 />
        </cfcase>
        <cfcase value="smalldatetime">
            <cfreturn IsDate(arguments.date) AND DateCompare(arguments.date, '1/1/1900') gte 0 AND DateCompare(arguments.date, '6/2/2079') lte 0 />
        </cfcase>
    </cfswitch>
</cffunction>

Nothing that someone else couldn't write, but useful. to save headaches.

 

Rounded Corners Code

A while back I mentioned that I had come up with some code to do rounded borders, but that I was holding it back as part of a larger release. Since then, I've not gotten as far with some of my other code ideas, and since I was asked nicely, I figured I'd release the code for rounded corners.

 

Image Object

Perhaps I've been overwhelmed by my recent reading on object-oriented design, but as I said in my last post, I thought an object that offered all the CF8 Image functions as methods of that object would be kind of nice. Despite the stumbling block of not being able to use onMissingMethod and Evaluate to create a solution, I applied a little brute force and hand coded it all. You can download it here:

Image.cfc

Version 0.3
  • Corrected for ImageDrawQuardicCurve() documentation errors (takes 7, not 9 as listed here).
  • Added masks to allow Yes/No and On/Off inputs to be passed as simple boolean values (true/false)

I've tested the basics, but I wont guarantee that it is completely bug free. When I find additional bugs, I'll put out new versions. I'll also be using this object as the bases for a new EffectsImage.cfc that will hold things like the mirroring effect.

 

Evaluate()'ing a Function with "Nothing" Returned

So, I'm plugging away at some cool image effect stuff, and I decided that it would be nice to wrap all my image functionality into an object, and that it would be cool to try CF8's new onMissingMethod function to implement the built in function set as methods of this new object. The overall effect would be really nifty and fun to use, but I hit a big old snag; the Evaluate() function fails with "nothing" returned.

 

Google YouTube Video Ads

You can see it below, but I'm testing out Google's YouTube video ad block, and I have to say that I'm unimpressed. AdSense seems to pick up on the content of my site pretty well, but this thing is just crazy. I've gotten more videos for models doing tryouts and artists painting "web 2.0" paintings then anything useful or interesting.

Any one else have thoughts on it, or how I can improve the accuracy of what videos it picks?

 

CF is not for Cookies

While ColdFusion uses cookies in some sophisticated ways (tracking sessions and what not), I found out today that because CF is case insensitive, it is inept at tracking cookies in certain situations.

 

More Entries

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.