c#方法生成mysql if方法(算工作日)
                        
                            时间:2021-07-01 10:21:17
                            帮助过:2人阅读
							                        
                     
                    
                    
                     static string retunSQl(
string s,
string e){
            
            return @"IF (
                    "+s+ 
">" +e+ 
@",
                    DATEDIFF(" + e + 
@", " + s + 
@") - FLOOR(
                        ABS(
                            DATEDIFF(
                                subdate(
                                    " + e + 
@",
                                    date_format(" + e + 
@", ‘%w‘) - 1
                                ),
                                 " + s + 
@"
                            ) / 7 *- 1
                        )
                    ) * 2 *- 1,
                    DATEDIFF(" + e + 
@",  " + s + 
@") - FLOOR(
                        ABS(
                            DATEDIFF(
                                subdate(
                                    " + s + 
@",
                                    date_format( " + s + 
@", ‘%w‘) - 1
                                ),
                                " + e + 
@"
                            ) / 7 *- 1
                        )
                    ) * 2
                )";
        }
使用方法:
retunSQl("2016-4-12","2016-4-14");
2天
retunSQl(‘2016-4-12‘,‘2016-4-18‘);
4天
不算周末
 
 
c#方法生成mysql if方法(算工作日)
标签: