From 71fd340f693b53397c8babf650ecdf849a44fe58 Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Thu, 2 Dec 2021 20:20:59 +0800 Subject: [PATCH] Time function optimization --- .../ResolveItems/MethodCallExpressionResolve.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs index a157e1f37..50af860e6 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve.cs @@ -878,19 +878,23 @@ namespace SqlSugar public string GeDateFormat(string formatString, string value) { - if (IsOracle()) + if (IsOracle()) { - return $"to_char({value},'{formatString}') "; + return $"to_char({value},'{formatString}') "; } - else if (formatString == "yyyy-MM-dd"&&IsSqlServer()) + else if (IsMySql()&& formatString == "yyyy-MM-dd") + { + return $"DATE_FORMAT({value}, '%Y-%m-%d')"; + } + else if (formatString == "yyyy-MM-dd" && IsSqlServer()) { return $"CONVERT(varchar(100),convert(datetime,{value}), 23)"; } - else if (formatString == "yyyy-MM-dd HH:mm:ss" && IsSqlServer()) + else if (formatString == "yyyy-MM-dd HH:mm:ss" && IsSqlServer()) { return $"CONVERT(varchar(100),convert(datetime,{value}), 120)"; } - else if (formatString == "yyyy-MM-dd hh:mm:ss" && IsSqlServer()) + else if (formatString == "yyyy-MM-dd hh:mm:ss" && IsSqlServer()) { return $"CONVERT(varchar(100),convert(datetime,{value}), 120)"; }