year show
how show just like this 2009-2010, 2014-2015 year in windows from c sharp
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 9, 2014, 5:52 AM
The basic code is:
int year = 2014; // or whatever
string yearToYear = String.Format("{0}-{1}", year, year+1);
However, suppose you're given a date and you need to know what financial year (from 1 April to 31 March) it falls into. Then you can do it like this:
DateTime dt = DateTime.Today; // or whatever
int year = dt.Year;
DateTime dt2 = new DateTime(year, 4, 1);
string fy;
if (dt >= dt2)
{
fy = String.Format("{0}-{1}", year, year+1);
}
else
{
fy = String.Format("{0}-{1}", year-1, year);
}