You are on page 1of 1

extract the month between two given dates

Dec 04, 2007 04:12 AM|LINK

hii all i am havie a database with given fileds like projectid,projectcode,projectname,startdat,enddate,etc.... my problem is to show all months and year between each projects startdate and enddate in a datagrd..and the table dont have month, year field.. i need to use sql quiery.. if anybody can help me in this matter.. it will be greatful.. thanks in advance..binoy Re: extract the month between two given dates
Dec 04, 2007 04:37 AM|LINK

Hi Try this Select datediff(mm,date,date1) from table_1 where mm - stands for months,,, other applicable values are dd (days), yy (years) date - start date date1 - end date For more info http://technet.microsoft.com/en-us/library/ms186724(SQL.100).aspx Re: extract the month between two given dates
Dec 04, 2007 04:40 AM|LINK

Hi on a second though, If i have not understood the question properly, this query allows you to get individual months from a given date SELECT (DATEPART(mm, startdate) ) AS MyDate FROM <YourTable> Again mm stands for month, dd - days and yy-year This gives you the "month" position (value of month) from each of the supplied dates. Hope any of these helps you. VJ If the reply answered your question please Mark it as "Answered". This would help people know that the question has been answered. Re: extract the month between two given dates
Dec 04, 2007 04:51 AM|LINK

hi u can use datepart(month,startdate) to get monthid and datename(month,startdate) to get monthname and year(startdate) or year(enddate) to get year (yearid) while selecting records between the dates u have to add the month field and the year field for that records by using the monthid and yearid and then u can group them

You might also like