diff --git a/src/Umbraco.Core/Persistence/Migrations/MigrationExpressionBase.cs b/src/Umbraco.Core/Persistence/Migrations/MigrationExpressionBase.cs index 7dde31d3e3..7dff959ade 100644 --- a/src/Umbraco.Core/Persistence/Migrations/MigrationExpressionBase.cs +++ b/src/Umbraco.Core/Persistence/Migrations/MigrationExpressionBase.cs @@ -76,6 +76,8 @@ namespace Umbraco.Core.Persistence.Migrations case TypeCode.UInt32: case TypeCode.UInt64: return val.ToString(); + case TypeCode.DateTime: + return SqlSyntax.FormatDateTime((DateTime) val); default: return SqlSyntaxContext.SqlSyntaxProvider.GetQuotedValue(val.ToString()); } diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/ISqlSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/ISqlSyntaxProvider.cs index 899a462172..056d9c1d9a 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/ISqlSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/ISqlSyntaxProvider.cs @@ -54,6 +54,7 @@ namespace Umbraco.Core.Persistence.SqlSyntax string DeleteConstraint { get; } string CreateForeignKeyConstraint { get; } string DeleteDefaultConstraint { get; } + string FormatDateTime(DateTime date, bool includeTime = true); string Format(TableDefinition table); string Format(IEnumerable columns); List Format(IEnumerable indexes); diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs b/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs index dcb7dc029c..6832be7d65 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/MySqlSyntaxProvider.cs @@ -191,6 +191,21 @@ ORDER BY TABLE_NAME, INDEX_NAME", return false; } + /// + /// This is used ONLY if we need to format datetime without using SQL parameters (i.e. during migrations) + /// + /// + /// + /// + /// + /// MySQL has a DateTime standard that is unambiguous and works on all servers: + /// YYYYMMDDHHMMSS + /// + public override string FormatDateTime(DateTime date, bool includeTime = true) + { + return includeTime ? date.ToString("YYYYMMDDHHmmss") : date.ToString("YYYYMMDD"); + } + public override string GetQuotedTableName(string tableName) { return string.Format("`{0}`", tableName); diff --git a/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs b/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs index 08d85e0573..7a56a461bc 100644 --- a/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs +++ b/src/Umbraco.Core/Persistence/SqlSyntax/SqlSyntaxProviderBase.cs @@ -251,6 +251,21 @@ namespace Umbraco.Core.Persistence.SqlSyntax return true; } + /// + /// This is used ONLY if we need to format datetime without using SQL parameters (i.e. during migrations) + /// + /// + /// + /// + /// + /// MSSQL has a DateTime standard that is unambiguous and works on all servers: + /// YYYYMMDD HH:mm:ss + /// + public virtual string FormatDateTime(DateTime date, bool includeTime = true) + { + return includeTime ? date.ToString("YYYYMMDD HH:mm:ss") : date.ToString("YYYYMMDD"); + } + public virtual string Format(TableDefinition table) { var statement = string.Format(CreateTable, GetQuotedTableName(table.Name), Format(table.Columns));