Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:10:51+00:00 2026-05-26T08:10:51+00:00

i have a sql code to find out the user’s last log in and

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:10:52+00:00Added an answer on May 26, 2026 at 8:10 am

    As you have said WL.IN_OUT is 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.

    <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>
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm an avid vim user and have started to write some SQL code recently.
I have a SQL Table Roles in DB. I want to find out if
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
I have the following SQL code that runs against a Change Request database. Each
I have an HTML textbox that contains some SQL code that I need executed.
Let's say I have to implement a piece of T-SQL code that must return
i have a sql server that i use and i am trying to code
I have a SQL Server table with 2 columns, Code and CodeDesc. I want
Following Uncle Bob's avice in Clean Code , I'd like to have no SQL
I have never hand-coded object creation code for SQL Server and foreign key decleration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.