TimeDiff without Weekends

  • Good Morning

    I am trying to get the time/date difference between 2 dates without any weekends here is the code I have that gives me the result exactly the way I need it except it adds weekends.

    CONCAT(

    FLOOR(HOUR(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')) / 24), ' days, ',

    MOD(HOUR(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')), 24), ' hours, ',

    MINUTE(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')), ' minutes, ',

    SECOND(TIMEDIFF('2012-08-05 09:56', '2012-08-02 11:20')), ' seconds')

    AS TimeDiff

  • Morning,

    Your code does not look like SQL Server as there is no TIMEDIFF function here. Is this an exercise for MySQL?

  • Hi Sorry, Yes it's MySQL. Not sure if I posted it at the right place..

  • I'm not sure if there is a function in MySQL.

    In T-SQL one way would be to create a calender-table which contains one record for each day for the past and next years. Include a column to mark which days are weekends you can join the table to each day and filter the days in a where clause exluding the weekends.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply