Skip to main content

Posts

Showing posts from January, 2014

c# - How to get the month name from month number

Month name from number The following asp.net c# example code demonstrate us how can we get month name from number. this examplecode also demonstrate us how can we get month name from a datetime object. bellow is the explain of example source code. We created a datetime object using DateTime.Today property. DateTime.Today property get the current date without time in the web server.DteTime.Month property gets the month number from a datetime object. so we uses the DateTime.Month property to get the month number fromtoday date that represent the current month of web server. At last we call the DateTimeFormatInfo.GetMonthName() method that returns the culture specific full name of the specified month based on theculture associated with the current DateTimeFormatInfo object. GetmonthName method require an integer type argument that represent month number. CultureInfo.DateTimeFormat property get or set a DateTimeFormatInfo that defines the cult...

c# - How to get the last day of month using a given date

DateTime get last day of month The following asp.net c# example code demonstrate us how can we get last day of a month programmaticallyat run time in an asp.net application. In this example code, we will see how can we get last day of a month froma specified DateTime object. By default, .net framework's DateTime class has no method or property to get last day of a month. So, we need to applyfew techniques to get last day of a month from a given date. At first, we need to extract the month from a given date. Thenwe need to get the last day of extracted month. We applied the following techniques to get the last day of a month; first, we add one month with the given date by usingDateTime.AddMonths() method. Then we create a new DateTime variable by using the month added DateTime object's year, monthand first day (day number 1) such as 2014/12/1(DateTime.Year/DateTime.Month/1). So, we get a new DateTime object which represent first d...

c# - How to add weeks to a DateTime object

DateTime add weeks The following asp.net c# example code demonstrate us how can we add one or more weeks with a DateTimeobject programmatically at run time in an asp.net application. By default, .net framework's DateTime Class have nomethod or property to add week with a DateTime object. So we need to go technically to add weeks with a date. We know that one week is equal to 7 days, two weeks is equal to 14 days, three weeks is equal to 21 daysand so on. .Net framework's DateTime Class DateTime.AddDays() method allow us to add specified days with a DateTimeobject. This method require to pass a parameter which hold number of days to add. So, we can use this AddDays()method to add weeks with a DateTime object. As example, if we want to add one week with a date then we can call the method as DateTime.AddDays(7) and if we want toadd three weeks with a DateTime object then we can call the method as DateTime.AddDays(21) and so on. We just ne...