To get the year from a DateTime column in your SQL database, use the YEAR() function. This function takes a single argument, which is the DateTime column you want to extract the year from. For example, if you wanted to get the year from the created_at column of your database, you would use the following query:
Let's look at a few examples of how this function can be used. Suppose you have a table called users with the following data:
If you wanted to get the year from the created_at column of this table, you would use the following query:
This query would return the results 2020, 2019, 2020, and 2018, since these are the years associated with each of the created_at values.
The YEAR() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.