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

Asked

Viewed 972 times

10

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

  • 5

    I think your question is a little confused.. for me, the first day of the month is always day 1 :P

  • 1

    @rLinhares, I want the name of the day (Monday, Tuesday, Wednesday.) first day of the month of December

  • @vnbrs, I edited the question

  • sorry @vnbrs, did there

5 answers

8


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.

  • 1

    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

You are not signed in. Login or sign up in order to post.