Page 1 of 1

How to get month in datetime field in database using C#

Posted: Tue Feb 02, 2010 2:24 pm
by Neo
To get month as a number,

Code: Select all

int theMonth = ((System.DateTime)yourDateTimeFieldObject).Month;
To get month as a string like November, December....

Code: Select all

int theMonth = ((System.DateTime)yourDateTimeFieldObject).ToString("MMMM");

Re: How to get month in datetime field in database using C#

Posted: Thu Feb 04, 2010 5:14 pm
by Neofriend
Or the way I've came to solve this issue is by using an excellent method namely DATEPART - very convenient and does all the work for you.