DateCompare returning incorrect result after moving to CF11 from CF9
I have a page which has been the same since CF7. Recently we moved our application to CF11 to support TLS1.2 and I've since noticed that this one particular bit of code has stopped functioning correctly and it's lead me down a weird road.
This is the following code block. It's meant to create date/time ranges for conditional statements and compare the current time against those ranges, performing a certain task.
<!--- Set date --->
<cfset thisDate = getDate()>
<!--- Determine what flight they should see. --->
<!--- If it's after 9am and before 10pm --->
<cfif thisDate GTE CreateDateTime(DatePart("yyyy",thisDate),DatePart("m",thisDate),DatePart("d",thisDate),9,0,0)
AND
thisDate LT CreateDateTime(DatePart("yyyy",thisDate),DatePart("m",thisDate),DatePart("d",thisDate),21,0,0)>
<cfset d1 = "#DatePart('m',thisDate)#/#DatePart('d',thisDate)#/#DatePart('yyyy',thisDate)# 9:00:00">
<cfset d2 = "#DatePart('m',thisDate)#/#DatePart('d',thisDate)#/#DatePart('yyyy',thisDate)# 21:00:00">
<!--- If it's after 10pm --->
<cfelseif thisDate GTE CreateDateTime(DatePart("yyyy",thisDate),DatePart("m",thisDate),DatePart("d",thisDate),21,0,0)>
<cfset d1 = "#DatePart('m',thisDate)#/#DatePart('d',thisDate)#/#DatePart('yyyy',thisDate)# 21:00:00">
<cfset d2 = "#DatePart('m',thisDate)#/#DatePart('d',thisDate)#/#DatePart('yyyy',thisDate)# 9:00:00">
<cfset d2 = DateAdd("d",1,d2)>
<!--- If it's before 9am --->
<cfelse>
<cfset d1 = "#DatePart('m',thisDate)#/#DatePart('d',thisDate)#/#DatePart('yyyy',thisDate)# 21:00:00">
<cfset d1 = DateAdd("d",-1,d1)>
<cfset d2 = "#DatePart('m',thisDate)#/#DatePart('d',thisDate)#/#DatePart('yyyy',thisDate)# 9:00:00">
</cfif>
The above code has always functioned correct, however since the move I've noticed it's no longer evaluating the current date/time as falling within the correct ranges. This morning at 11:15am I checked and it was not firing the first if statement, but instead firing the else statement. Meaning it thought it was before 9:00am.
I assumed this meant that perhaps in CF11 I'm not able to just evaluate the times using LTE and GTE. So I thought instead that I would test using DateCompare. So I wrote the following:
<cfset thisDate = getDate()>
<cfset date1 = CreateODBCDateTime(thisDate)>
<cfset date2 = CreateODBCDateTime(CreateDateTime(DatePart("yyyy",thisDate),DatePart("m",thisDate),DatePart("d",thisDate),9,0,0))>
<cfoutput>
date1: #date1#<br />
date2: #date2#<br />
<br />
DateCompare: #DateCompare(date1,date2)#<br />
GTE Evaluation: #date1 GTE date2#<br />
</cfoutput>
Now this is where it gets weird. The output from the above is:
date1: {ts '2018-06-20 15:12:00'}
date2: {ts '2018-06-20 09:00:00'}
DateCompare: -1
GTE Evaluation: NO
The date compare should output "1" and the GTE evaluation should output "YES" since they are the same day and date1 is 3pm and date2 is 9am.
Can anyone help me out here? This is mind boggling for me.
Thanks so much,
Mike
