Getting only Month and Year from SQL DATE

0 votes
I want to access only Month.Year from Date field in SQL Server.
Sep 16, 2022 in Database by Kithuzzz
• 38,010 points
1,374 views

1 answer to this question.

0 votes

In addition to the advice already given, I can deduce the following possibility from your question:
- You still want the result to be a date.
- But you want to 'discard' the Days, Hours, etc
- Leaving a year/month only date field.

SELECT
   DATEADD(MONTH, DATEDIFF(MONTH, 0, <dateField>), 0) AS [year_month_date_field]
FROM
   <your_table>

This subtracts the amount of partial months from a base date (zero) and then adds them. Rounding down to the month that the date is in does as a result.

I hope this helps you.

answered Sep 17, 2022 by narikkadan
• 63,420 points

Related Questions In Database

0 votes
1 answer

Get month and year from date cells Excel

The steps to modify the date format ...READ MORE

answered Mar 30, 2022 in Database by gaurav
• 23,260 points
567 views
0 votes
0 answers

Get week day name from a given month, day and year individually in SQL Server

I'm attempting to get a day name ...READ MORE

Aug 13, 2022 in Database by Kithuzzz
• 38,010 points
969 views
0 votes
0 answers

How to group by month from Date field using sql

How can I only group by month ...READ MORE

Aug 20, 2022 in Database by Kithuzzz
• 38,010 points
789 views
0 votes
0 answers

How to return only the Date from a SQL Server DateTime datatype

SELECT GETDATE() Returns: 2008-09-22 15:24:13.790 I want that date part ...READ MORE

Sep 6, 2022 in Database by Kithuzzz
• 38,010 points
374 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,020 points
600 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4, 2022 in Database by Vaani
• 7,020 points
329 views
0 votes
1 answer

What is a stored procedure?

A stored procedure is a set of ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,060 points
805 views
0 votes
1 answer

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

At the top level there are mainly ...READ MORE

answered Feb 4, 2022 in Database by Neha
• 9,060 points
1,660 views
0 votes
1 answer

How to extract only the year from the date in sql server 2008?

To obtain the year from the given ...READ MORE

answered Sep 15, 2022 in Database by narikkadan
• 63,420 points
512 views
0 votes
1 answer

Get list of databases from SQL Server

Execute: SELECT name FROM master.sys.databases I hope this helps ...READ MORE

answered Sep 10, 2022 in Database by narikkadan
• 63,420 points
367 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP