Here this code, your can get previous month's first and last day. It's simple static void Main( string [] arg) { var year = DateTime .Today.Year; var month = DateTime .Today.Month; var firstDate = new DateTime (year, month, 1).AddMonths(-1); var lastDate = new DateTime (year, month, 1).AddDays(-1); Console .WriteLine( "First day Previous Month: {0}" , firstDate); Console .WriteLine( "Last day Previous Month: {0}" , lastDate); var lastday = GetMonthLastDate ( 2015 , 6 ); Console .WriteLine( "Last day : {0}" , lastDate); Console .ReadLine(); } You can use below method to get last date of any month of the any year. private DateTime GetMonthLastDate( int year, int month) { return new DateTime (year, month, DateTime .DaysInMonth(year, month)); }
Comments
Post a Comment