Another approach is to use the dateDiff() SQL function.  That way, you can
determine the level of precision at which you are comparing.

For example, run the following scripts against any SQL database.  You will
see that the result is quite different.  If you only want to know two date
values are on the same day regardless of time, then using dateDiff() may be
safer.

DECLARE @dateVal_1 DATETIME
declare @dateVal_2 DATETIME
SET @dateVal_1 = '2009-12-22 00:01:01.000'
SET @dateVal_2 = '2009-12-22 23:59:59.000'

/* Using the good old greater or less than signs */
SELECT  CASE WHEN getDate() > @dateVal_1
THEN 'today is later than date value 1!'
WHEN getDate() = @dateVal_1
then 'today is the same as date value 1!'
ELSE 'today is earlier than date value 1!'
END AS date_compare_result_1,
CASE WHEN getDate() > @dateVal_2
THEN 'today is later than date value 2!'
WHEN getDate() = @dateVal_2
then 'today is the same as date value 2!'
ELSE 'today is earlier than date value 2!'
END AS date_compare_result_2

/* Using dateDiff() */
SELECT CASE WHEN dateDiff(dd,@dateVal_1,getDate()) > 0
THEN 'today is later than date value 1!'
WHEN dateDiff(dd,@dateVal_1,getDate()) = 0
then 'today is the same as date value 1!'
ELSE 'today is earlier than date value 1!'
END AS date_compare_result_1,
CASE WHEN dateDiff(dd,@dateVal_2,getDate()) > 0
THEN 'today is later than date value 2!'
WHEN dateDiff(dd,@dateVal_2,getDate()) = 0
then 'today is the same as date value 2!'
ELSE 'today is earlier than date value 2!'
END AS date_compare_result_2



On Mon, Dec 21, 2009 at 9:21 AM, Damo Drumm <damien.dr...@quinn-group.com>wrote:

>
> Thanks alot for all your help,
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329327
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to