Mysql : how to calculate business hrs between two timestamps and neglect weekends

后端 未结 4 1671
南笙
南笙 2021-02-04 06:38

My table has sample data and I need to calculate business hrs between two timestamps in two columns. Business hrs : 9:00am to 5:00pm and neglect Saturday and Sunday, I am not co

4条回答
  •  逝去的感伤
    2021-02-04 07:16

    Use datediff to calculate the diff between the start and the end time and then subtract (date_add with negative hours) the non-working hours: 24 for weekend days, 16 for working days expect the ending and starting day which needs additional calculation. Whether a day is weekend day or not, can be specified with the dayofweek method.

提交回复
热议问题