Browse Source

Update mysql date format

pull/32/head
sunkaixuan 2 years ago
parent
commit
13eb3afa73
  1. 15
      Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_BaseDateFomat.cs

15
Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_BaseDateFomat.cs

@ -131,6 +131,21 @@ namespace SqlSugar
{
return string.Format("FORMAT({0},'{1}','en-US')", value, formatString);
}
else if (IsMySql()&& !formatString.Contains("%"))
{
var newFormt = formatString
.Replace("yyyy", "%Y")
.Replace("yy", "%Y")
.Replace("MM", "%m")
.Replace("M", "%m")
.Replace("dd", "%d")
.Replace("HH", "%H")
.Replace("hh", "%h")
.Replace("mm", "%i")
.Replace("ss", "%s")
.Replace("fff", "%f");
return $"DATE_FORMAT({value}, '{newFormt}')";
}
var parameter = new MethodCallExpressionArgs() { IsMember = true, MemberValue = DateType.Year };
var parameter2 = new MethodCallExpressionArgs() { IsMember = true, MemberName = value };
var parameters = new MethodCallExpressionModel() { Args = new List<MethodCallExpressionArgs>() { parameter2, parameter } };

Loading…
Cancel
Save