Get month from nvarchar columnMMManoj Mandal7yAsked Aug 4, 2019, 10:32 PM EDT9 answersShareLinkedInXCopy linkSavei have nvarchar column as 4/23/2019 from this i want month 4
Get month from nvarchar columnMMManoj Mandal7yAsked Aug 4, 2019, 10:32 PM EDT9 answersShareLinkedInXCopy linkSavei have nvarchar column as 4/23/2019 from this i want month 4
Aakash MauryaRank #114 · 19.8K reputation7y agoPosted Aug 4, 2019, 10:44 PM EDT+1Try SELECT MONTH(CONVERT(NVARCHAR, '4/23/2019', 105)) Working code +1
MMManoj MandalRank #3,495 · 415 reputation7y agoPosted Aug 4, 2019, 11:10 PM EDT+1SELECT * FROM H_BABY_MOTHER WHERE MONTH(CONVERT(NVARCHAR,B_DELIVERYDATE,105))='07' this is my query B_DELIVERYDATE is NVARCHAR COLUMN +1
Chittaranjan SwainRank #216 · 11.3K reputation7y agoPosted Aug 4, 2019, 11:23 PM EDT0hi manoj, Try below queries, SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, ), 0) AS [year_month_date_field] FROM or, SELECT YEAR(yourDateField), MONTH(yourDateField), DAY(yourDateField); or, https://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/0
MMManoj MandalRank #3,495 · 415 reputation7y agoPosted Aug 4, 2019, 11:40 PM EDT0Akash still it is not working i am using sql server 2008 R2 0
Aakash MauryaRank #114 · 19.8K reputation7y agoPosted Aug 4, 2019, 11:47 PM EDT0Just give me the error text that you are getting. I have SQL version greater than SQL 2008. Error message will help me more 0
Sonu GuptaRank #1,261 · 1.4K reputation7y agoPosted Aug 6, 2019, 1:03 AM EDT0Hi Manoj, 1. For date format 'mm/dd/yyyy' use this query Your query like this - SELECT * FROM H_BABY_MOTHER WHERE MONTH(CONVERT(DATE,B_DELIVERYDATE))='07' 2. For date format 'dd/mm/yyyy' use this query select MONTH(CONVERT(DATE,'12-01-2019',103))0Tamal MarickRank #4,584 · 336 reputation7y agoPosted Aug 6, 2019, 1:55 AM EDT0If the date format is fixed, like mm/dd/yyyy, then you can try this (without convert). SELECT SUBSTRING('4/23/2019',0,CHARINDEX('/','4/23/2019',0))0Aakash MauryaRank #114 · 19.8K reputation7y agoPosted Aug 4, 2019, 11:13 PM EDT-1Your query should be like SELECT * FROM H_BABY_MOTHER WHERE MONTH(CONVERT(NVARCHAR,B_DELIVERYDATE,105))=7 Month returns numeric data. -1Amit MohantyRank #112 · 20K reputation7y agoPosted Aug 6, 2019, 7:56 PM EDT-1Hey try this There are two SQL function to do it:DATEPART()MONTH(). SELECT MONTH('4/23/2019') [month]; ORSELECT DATEPART(MM,'4/23/2019') [month]; -1Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tamal MarickRank #4,584 · 336 reputation7y agoPosted Aug 6, 2019, 1:55 AM EDT0If the date format is fixed, like mm/dd/yyyy, then you can try this (without convert). SELECT SUBSTRING('4/23/2019',0,CHARINDEX('/','4/23/2019',0))0
Aakash MauryaRank #114 · 19.8K reputation7y agoPosted Aug 4, 2019, 11:13 PM EDT-1Your query should be like SELECT * FROM H_BABY_MOTHER WHERE MONTH(CONVERT(NVARCHAR,B_DELIVERYDATE,105))=7 Month returns numeric data. -1
Amit MohantyRank #112 · 20K reputation7y agoPosted Aug 6, 2019, 7:56 PM EDT-1Hey try this There are two SQL function to do it:DATEPART()MONTH(). SELECT MONTH('4/23/2019') [month]; ORSELECT DATEPART(MM,'4/23/2019') [month]; -1
Aakash MauryaRank #114 · 19.8K reputationPosted Aug 4, 2019, 10:44 PM EDT
Manoj MandalRank #3,495 · 415 reputationPosted Aug 4, 2019, 11:10 PM EDT
Chittaranjan SwainRank #216 · 11.3K reputationPosted Aug 4, 2019, 11:23 PM EDT
Manoj MandalRank #3,495 · 415 reputationPosted Aug 4, 2019, 11:40 PM EDT
Aakash MauryaRank #114 · 19.8K reputationPosted Aug 4, 2019, 11:47 PM EDT
Sonu GuptaRank #1,261 · 1.4K reputationPosted Aug 6, 2019, 1:03 AM EDT
Tamal MarickRank #4,584 · 336 reputationPosted Aug 6, 2019, 1:55 AM EDT
Aakash MauryaRank #114 · 19.8K reputationPosted Aug 4, 2019, 11:13 PM EDT
Amit MohantyRank #112 · 20K reputationPosted Aug 6, 2019, 7:56 PM EDT
DATEPART()
MONTH().
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts