i have a sql code to find out the user’s last log in and log out, but the log IN and OUT are defined by special variable #in_out# anyway here is the code:
SELECT DISTINCT
0 AS TIP,
CP.PARTNER_ID P_ID,
CP.COMPANY_PARTNER_NAME P_NAME,
CP.COMPANY_PARTNER_SURNAME P_SURNAME,
WL.PARTNER_ID W_ID,
WL.DOMAIN_NAME DOMAIN,
WL.IN_OUT_TIME IN_OUT_TIME,
WL.IN_OUT IN_OUT,
C.FULLNAME C_NAME
FROM
COMPANY_PARTNER CP
LEFT OUTER JOIN WRK_LOGIN WL ON WL.PARTNER_ID = CP.PARTNER_ID
LEFT OUTER JOIN COMPANY C ON C.COMPANY_ID=CP.COMPANY_ID
WHERE
<cfif isdate(attributes.start_date)>WL.IN_OUT_TIME >= #attributes.start_date# AND</cfif>
<cfif isdate(attributes.finish_date)>WL.IN_OUT_TIME < #dateadd('d',1,attributes.finish_date)# AND</cfif>
<cfif len(attributes.domain_name)>WL.DOMAIN_NAME = '#attributes.domain_name#' AND</cfif>
<cfif len(attributes.in_out)>WL.IN_OUT = #attributes.in_out# AND</cfif>
WL.DOMAIN_NAME IS NOT NULL
GROUP BY
CP.PARTNER_ID,WL.PARTNER_ID,WL.IN_OUT_TIME,WL.IN_OUT,CP.COMPANY_PARTNER_NAME,CP.COMPANY_PARTNER_SURNAME,WL.DOMAIN_NAME,C.FULLNAME
and the table:
<cfoutput query="get_wrk_login" startrow="#attributes.startrow#" maxrows="#attributes.maxrows#" group="P_ID">
<cfif in_out eq 1><cfset date1 = '#in_out_time#'></cfif>
<cfif in_out eq 0><cfset date2 = '#in_out_time#'></cfif>
<cfif not isdefined('date2')><cfset online_time = 30><cfelse><cfset online_time = datediff("n", date1, date2)></cfif>
<tr height="20" onMouseOver="this.className='color-light';" onMouseOut="this.className='color-row';" class="color-row">
<td width="100" align="center">#dateformat(in_out_time,'dd/mm/yyyy')# #timeformat(dateadd('h',2,in_out_time),'HH:MM')#</td>
<td>#p_name# #p_surname# #online_time#</td>
<td align="center"><cfif tip eq 0>Kurumsal<cfelse>Biriyesel</cfif></td>
<td width="130">#left(C_NAME,20)#</td>
<td width="100">#domain#</td>
<td align="center"><cfif in_out eq 1><cf_get_lang_main no='142.Giriş'><cfelse><cf_get_lang_main no='19.Çıkış'></cfif></td>
</tr>
</cfoutput>
the problem is that i cant set the date1 and date2 to a last log in and out, because the time is defined just once in a loop, and said to be IN or OUT log, if in the loop it was defined in the same time the LOG IN and LOG OUT time, i would have easily datediff em, but it defined once in a loop, i hope u understood me ^.^ but now im getting the result even minus minutes )) so it is deffinetly wrong, thus im asking for help, and thank you all for help!
As you have said
WL.IN_OUTis a BIT field, so can only ever be 1 or 0.This means that only date1 OR date2 can be defined. They can not both be defined at the same time.
What you are saying in the code below is that if date2 is defined then get the difference between date1 and date2. If date2 is defined, date1 will never be defined, and vice versa.
From the query you provided above it is not possible to get the difference between the login and logout date, because you only have 1 date,
WL.IN_OUT_TIME IN_OUT_TIME, which is going to be either the login, or logout date.