Ciao a tutti,
dovrei costruirmi una stringa del tipo YYYYMMDD che contenga l'ultimo giorno del mese precedente alla data odierna.
Avevo pensato ad una cosa del tipo:
DateTime oggi = DateTime.Now;
int mese = oggi.Month;
string DefaultData = string.Empty;
if (mese==1 || mese==2 || mese==4 || mese==6 || mese==8 || mese==9 || mese==11)
{
DefaultData = oggi.Year + (oggi.Month-1) + "31";
}
else if (mese == 3)
{
DefaultData = oggi.Year + (oggi.Month - 1) + "28";
}
else
DefaultData = oggi.Year + (oggi.Month - 1) + "30";
Mi sembra però un po' macchinosa, senza contare che in questo modo non posso gestire gli anni bisestili.
Qualcuno ha un'idea migliore?
Grazie