To Get MonthName from a Date Field from a table using Stored Procedure

//Assuming that the field name is Bdate

convert (varchar,(select DateName(month,dateadd(month,month(Bdate),0)-1)),103)

To get Current Month name

There are two ways to get the Current Month Name from the Current Date.

1)  Using Globliziation

System.Globalization.DateTimeFormatInfo d = new System.Globalization.DateTimeFormatInfo();
string month = d.MonthNames[DateTime.Now.Month-1];

2) Using new date object as follow

string MonthName = GetMonthName(DateTime.Now.Month);
static string GetMonthName(int monthNum)
{
return GetMonthName(monthNum, false);
}
static string GetMonthName(int monthNum, bool abbreviate)
{
if (monthNum < 1 || monthNum > 12)
throw new ArgumentOutOfRangeException(”monthNum”);
DateTime date = new DateTime(1, monthNum, 1);
if (abbreviate)
return date.ToString(”MMM”);
else
return date.ToString(”MMMM”);
}

To check whether the user’s b’day is in the current month or not using stored prcedure

//Assuming the table name as Users and fieldname as Bdate

select  * from Users
where month(Bdate)=month(getdate())
and day(Bdate)between Day(getdate())
and day(dateadd(day,30,getdate()))

Follow

Get every new post delivered to your Inbox.