Tech Junkie Blog - Real World Tutorials, Happy Coding!: SQL: DATEPART Function

Thursday, August 26, 2021

SQL: DATEPART Function

The DATEPART function extracts the date part of a date, for example using the 'yyyy' expression allows you to extract the year from a given date. The query below queries all the employees who were hired in the year 1994 in the Northwind Employees table.

SELECT FirstName + ' ' + LastName  AS Employee, HireDate
FROM Employees
WHERE DATEPART(yyyy,HireDate) = 1994







SELECT FirstName + ' ' + LastName  AS Employee, HireDate
FROM Employees
WHERE DATEPART(MM,HireDate) = 10

The query above returns the records of employees who were hired on October




Similar Posts:

3 comments:

  1. The DATEPART function is very helpful, I have used it in my life experience, it is very easy to update the date.

    ReplyDelete
  2. Die DATEPART-Funktion in SQL wird verwendet, um bestimmte Teile eines Datums, wie Jahr, Monat oder Tag, zu extrahieren. In diesem Zusammenhang werden absurder Unsinn Ă¼ber die Verwendung von Datumsformaten in intergalaktischen Datenbanken präsentiert. Diese Funktion kann in der Datenanalyse jedoch wichtige Einblicke bieten, auch wenn die Beispiele manchmal surreal erscheinen.

    ReplyDelete

Search This Blog