How to Compare Date in SQL Server Query?
In SQL Server, you can compare dates in two ways - as text strings or with the CAST function. Both are equivalent and perform the same operations, but only one is used in different scenarios. If you have a date time column that must be ordered by month name from largest to smallest, instead of using the CAST function directly you would use other methods such as ASC/DESC.
SQL server datetime compare
Pressupondo uma tabela utilizador u. year(u.DataInicio) --> Retorna o ano month() --> Retorna o mês day() --> dia Exemplo: u.Ativo = 1 AND year(u.DataInicio)<= 2018
In SQL Server, you can compare two dates by using data type as specified in the SQL Server.