locked
how to check tow times if they are equal RRS feed

  • Question

  • User-1634604574 posted

    i have these two times i want they are equal how can make them equal to each other

    set @total_working_hour=(SELECT CONVERT(varchar, DATEADD(minute, DATEDIFF(minute, CAST('7:30' as time),CAST('11:30' as time)), 0), 108) )
    if @total_working_hour=( SELECT CAST(CONVERT(VARCHAR,DATEADD(SECOND, @Working_Hours_Threshold_for_Half_Day * 3600, 0),108) AS TIME) ) begin update Attendance set Status='Half Day' where attendance_date=@current_date and Attendance.Employee_ID=@Employee end

    result of @total_working_hour=04:00:00

    result of  SELECT CAST(CONVERT(VARCHAR,DATEADD(SECOND, @Working_Hours_Threshold_for_Half_Day * 3600, 0),108) AS TIME) =04:00:00.0000000

    how can i make them equal

    Monday, July 20, 2020 5:37 AM

Answers

  • User-939850651 posted

    Hi zhyanadil.it,

    You can convert them to the same type, which will make them equal.

    And for testing, I set @Working_Hours_Threshold_for_Half_Day to 4.

    It's like this:

    SELECT CONVERT(time, DATEADD(minute, DATEDIFF(minute, CAST('7:30' as time),CAST('11:30' as time)), 0), 108)
    its result => 04:00:00.0000000 SELECT CONVERT(time,DATEADD(SECOND, 4 * 3600, 0),108)
    its result => 04:00:00.0000000

    or you could convert the data type to varchar, and the result => 04:00:00

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 20, 2020 7:48 AM