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 in Database by Kithuzzz
• 11,640 points
18 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 by narikkadan
• 19,680 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 in Database by gaurav
• 18,960 points
55 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 in Database by Kithuzzz
• 11,640 points
59 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 in Database by Kithuzzz
• 11,640 points
64 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 in Database by Kithuzzz
• 11,640 points
27 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 in Database by Vaani
• 7,020 points
119 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 in Database by Vaani
• 7,020 points
44 views
0 votes
1 answer

What is a stored procedure?

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

answered Feb 4 in Database by Neha
• 8,920 points
214 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 in Database by Neha
• 8,920 points
145 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 in Database by narikkadan
• 19,680 points
42 views
0 votes
1 answer

SQL query - Dept and Employee table, some departments may not have managers

Yes, even though I like using JOINs, ...READ MORE

answered Sep 16 in Database by narikkadan
• 19,680 points
22 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP