extract year, month, 1st date of the month

Shambhu Rai 1,411 Reputation points
2022-08-10T17:27:46.14+00:00

Hi Expert,

I want to extract year, month, 1st date of the month using only extract function or adddate

create tab1
(col1, date)

insert into tab1
values('02/02/2022')

col1
02/02/2022

expected output
01/02/2022(dd/mm/yyy)

Regards

Azure SQL Database
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,066 questions
Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Jingyang Li 5,896 Reputation points Volunteer Moderator
    2022-08-10T17:35:35.08+00:00

    At minimum before you post, you need to test your own script.
    create table tab1
    (col1 int, date date)

    insert into tab1  
    values(1,'02/02/2022')  
    select * , format(date,'01/MM/yyyy') firstofMonthddMMyyyy   
    from tab1  
      
    --or  
    

    select * , try_convert(varchar(10),dateadd(day,1,eomonth(date,-1)),103) firstofMonthddMMyyyy
    from tab1

    drop table tab1  
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2022-08-10T18:31:48.467+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.