Year show
how show just like this 2009-2010, 2014-2015 year in windows from c sharp
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 9, 2014, 12:52 AM EST
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);
}