diff --git a/app/filter/filtercontroller.cpp b/app/filter/filtercontroller.cpp index ec679c839..d9ee12edc 100644 --- a/app/filter/filtercontroller.cpp +++ b/app/filter/filtercontroller.cpp @@ -262,7 +262,14 @@ QString FilterController::buildFieldExpression( const FieldFilter &filter ) cons if ( value.typeId() == QMetaType::QDateTime ) if ( isDateFilterDateTime( filter.filterId ) ) - expressionCopy.replace( QStringLiteral( "@@value@@" ), QgsExpression::quotedString( value.toDateTime().toUTC().toString( TIMESTAMP_FORMAT ) ) ); + { + // check if the DateTime contains milliseconds + const QDateTime utcDateTime = value.toDateTime().toUTC(); + const QString dateTimeFormat = utcDateTime.time().msec() != 0 + ? TIMESTAMP_FORMAT + : QStringLiteral( "yyyy-MM-ddTHH:mm:ssZ" ); + expressionCopy.replace( QStringLiteral( "@@value@@" ), QgsExpression::quotedString( utcDateTime.toString( dateTimeFormat ) ) ); + } else expressionCopy.replace( QStringLiteral( "@@value@@" ), QgsExpression::quotedString( value.toDate().toString( DATE_FORMAT ) ) ); else @@ -358,7 +365,14 @@ QString FilterController::buildFieldExpression( const FieldFilter &filter ) cons // QML always returns QDateTime so we can't differentiate based on type if ( value.typeId() == QMetaType::QDateTime ) if ( isDateFilterDateTime( filter.filterId ) ) - expressionTemplate.replace( QStringLiteral( "@@value@@" ), QgsExpression::quotedString( value.toDateTime().toUTC().toString( TIMESTAMP_FORMAT ) ) ); + { + // check if the DateTime contains milliseconds + const QDateTime utcDateTime = value.toDateTime().toUTC(); + const QString dateTimeFormat = utcDateTime.time().msec() != 0 + ? TIMESTAMP_FORMAT + : QStringLiteral( "yyyy-MM-ddTHH:mm:ssZ" ); + expressionTemplate.replace( QStringLiteral( "@@value@@" ), QgsExpression::quotedString( utcDateTime.toString( dateTimeFormat ) ) ); + } else expressionTemplate.replace( QStringLiteral( "@@value@@" ), QgsExpression::quotedString( value.toDate().toString( DATE_FORMAT ) ) ); else