Search code examples
sql-server-2008

How to check if datetime happens to be Saturday or Sunday in SQL Server 2008


Given a datetime, is there a way we can know it happens to be a Saturday or Sunday.

Any ideas and suggestions are appreciated!


Solution

  • Many ways to do this, you can use DATENAME and check for the actual strings 'Saturday' or 'Sunday'

    SELECT DATENAME(DW, GETDATE())
    

    Or use the day of the week and check for 1 (Sunday) or 7 (Saturday)

    SELECT DATEPART(DW, GETDATE())