How to get the name of day of the week of the first day of the month?

10

How do I get the name (Monday, Tuesday, Wednesday ...) from the first day of December from the current date?

    
asked by anonymous 17.10.2017 / 15:47

5 answers

8

You can also use FORMAT as well. See:

DECLARE @Data DATETIME = '2017-12-01 00:00:00'
SELECT FORMAT(@Data, 'dddd') AS dia_semana

The return:

dia_semana
-------------
Friday

The format dddd refers to the day of the week. The DATENAME , quoted in the response from the @ MarconcilioSouza can be used to get the name of the month and year as well. The format I used is to get the day of the week and only.

17.10.2017 / 16:18
6

If you already know the date by using:

SELECT DAYNAME('2017-10-16');

If you need the date in Portuguese and your bank has not configured you can use it before the query like this:

SET lc_time_names = 'pt_BR';

Just take care because if user, SET will have to return to the default language after returning the query.

    
17.10.2017 / 17:06
4

If you want to leave the month flexible, you can leave it in a variable, part of the example:

declare @mes varchar(2) = '12'
select DATENAME(weekday, '2017-' + @mes + '-01') as dia_semana
    
18.10.2017 / 20:04
3

You can mount the query as follows.

SELECT (DATENAME(dw, CAST('12' AS VARCHAR) + '/' + CAST('1' AS VARCHAR)  + '/'  + CAST(DATEPART(yy, getdate()) AS VARCHAR)) )
    
17.10.2017 / 16:03
0

In this case you can also use this:

SET @var := year(now());
Select @var, DAYNAME(CONCAT_WS('-', @var,'12-01'));
    
22.10.2017 / 19:14