Hi all,
here i want a function for variables fromdate and todate.
i am passing month and year as parameters for function and i want to return fromdate,todate from that function as
if i pass month as 01 & year as 2009 then i want fromdate as "01/01/2009" and todate as "31/01/2009"
if i pass month as 02 & year as 2012 then i want fromdate as "01/02/2012" and todate as "29/02/2012" means it need to check leap year also
if i pass month as 04 & year as 2009 then i want fromdate as "01/04/2009" and todate as "30/02/2009"
please give me some code for this
thank you...
Loading
Jan MontanoPosted Jan 9, 2009, 12:12 AM
int year = 2009;
int daysInMonth = DateTime.DaysInMonth(year, month);
DateTime fromDate = new DateTime(year, month, 1, 0, 0, 0);
DateTime toDate = new DateTime(year, month, daysInMonth, 0, 0, 0);
Console.WriteLine(fromDate.ToString("dd/MM/yyyy"));
Console.WriteLine(toDate.ToString("dd/MM/yyyy"));