Date Subtraction or Difference

Sometimes you need to know the differences between two dates in days months years whatever.

SQL SERVER


select datediff(day,date1, date2) as days_diff,
datediff(month,date1, date2) as months_diff...

Can also do year, quarter, week, hour, minute, and second dateparts.
Dates can be hard coded or column names.

Coldfusion Function

#DateDiff("datepart", "date1", "date2")#
datepart (yyyy, q, m, w, h, n, s)

JavaScript

A little tricker so further research may be needed to get the expected results.
var DateDiff = {

inDays: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();

return parseInt((t2-t1)/(24*3600*1000));
},

JQuery

var day_diff = datediff("day", date1, date2);

Posted in Code, Coldfusion, Javascript, JQuery, Snippets, SQL | Tagged | Leave a comment

SQL using case to Identify blanks vs NULLs

I had a strange issue driving me nuts today. I had data with null values and could use isNull to capture most of them and assign a new value to the field. However about 10 records would not accept the isnull logic. Finally after about 2 hours of beating the keyboard to death I finally realized the field was not null but contained blanks. So here is the code that can help if you run into this same situation.


select CASE _fieldname_
When NULL Then 'missing'
When '' Then 'spaces'
Else _fieldname_
END as _fieldname_
from tablename

* Replace the _fieldname_ with your fieldname containing blanks and nulls

Posted in Code, Snippets, SQL | Tagged , , , | Leave a comment

New Website – HonestAutoQuote.com

I built a new website for a long time client. Check out HonestAutoQuote.com if you need a fast free honest auto insurance quote. There are no gimmicks, no promises of freebees like 1 in 100 wins a gift card, and no bait and switch. Just a plain old fashioned business with integrity.

Site built using WordPress using special plugins for the forms. Base template is TwentyTen with modifications to the header and some layout elements. I also designed the logo for the site.

Posted in my portfolio, News | Leave a comment

Coldfusion CFC error messages

CFC’s are a wonderful thing in the world of Coldfusion Apps. They allow you append/display information without refreshing the page, deliver realtime queries of data, or display messages when users require guidance. They are wonderful until they break.

If you edit a query and get error messages, you either made a mistake and need to edit the CFC again, or are missing parameters.

If however your CFCs have been functioning fine for quite a while and you are suddenly getting errors on all your apps with CFC linked content, then you need to restart your CF services on your web server and reset the IIS connection too. If that does not clear the issue, make sure your database server is not the culprit. As a last resort check your browser. Did you upgrade or change it recently, which may have turned off Javascript functions.

Posted in Coldfusion, Problems & Fixes | Leave a comment

Coldfusion Query of Queries to Join two datasets

I had an issue where I needed to join data from two different datasets with out having an ODBC connection created by the admin.
I ran the two queries in thier respective databases then used query of queries to join them. This should work with differing types of databases like Oracle vs SQL Server.

Example (without brackets):

// query dataset 1
cfquery name="q1" dataset="ds1"
select emp_id, first name, last name
from tbl
/cfquery

//query dataset 2
cfquery name="q2" dataset="ds2"
select emp_id, salary
from tbl
/cfquery

// now use query of queries to merge the results
cfquery name="q3" dbtype="query"
select q1.emp_id, q1.first_name, q1.lastname, q2.salary
from q1, q2
where q1.emp_id = q2.emp_id
/cfquery

//output results
cfdump var="#q3#"

Posted in Code, Coldfusion, Snippets | Leave a comment