10
How do I get the name (Monday, Tuesday, Wednesday...) of the first day of the month of December from the current date?
10
How do I get the name (Monday, Tuesday, Wednesday...) of the first day of the month of December from the current date?
8
You can use the FORMAT
too. 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
is related to the day of the week. The DATENAME
, quoted in the reply of @Marconciliosouza can be used to get the name of the month and the year as well. The format I used is to get the day of the week and only.
6
If you already know the date by using the:
SELECT DAYNAME('2017-10-16');
If you need the date in English and your database has not been configured you can use it before the query like this:
SET lc_time_names = 'pt_BR';
Just take care because user SET will have to return to the default language after returning the query.
edited the question.
In this case you can catch the current year like this: select year(now());
I do not understand why people make a thousand codes, and so simple to do it! That should be the answer accepted!
4
If you want to make the month flexible, you can leave it in a separate variable, follow the example:
declare @mes varchar(2) = '12'
select DATENAME(weekday, '2017-' + @mes + '-01') as dia_semana
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)) )
this script is only bringing in the current month, but I want to bring it this way, but from the month of December
@Renanbessa, see that I am manipulating the date the month is in the first CAST('12' AS VARCHAR)
@Marconciliosouza, I edited the question
0
In that case you can also use it like this:
SET @var := year(now());
Select @var, DAYNAME(CONCAT_WS('-', @var,'12-01'));
That’s if it were Mysql
Which bank are you using ?
this on the question tag.
I didn’t pay attention, sorry. I’ll do it in SQL. Thank you.
Browser other questions tagged sql sql-server date
You are not signed in. Login or sign up in order to post.
I think your question is a little confused.. for me, the first day of the month is always day 1 :P
– rLinhares
@rLinhares, I want the name of the day (Monday, Tuesday, Wednesday.) first day of the month of December
– Renan Bessa
@vnbrs, I edited the question
– Renan Bessa
sorry @vnbrs, did there
– Renan Bessa