I need to set the day of year for a DateTime, I am getting the day of year from a past date say ‘5/7/2000″ that day is 128, I now want to set another DateTime with that day 128 so I can get the day of that date this year which would be Monday. Can you help me?
Here is the code I am trying, I have the date bound in a listbox and I am tapping it to get the selected date
string selectedTap = "";
int dayOfYear;
DateTime dayOfThisYear;
var selected = listBoxItem.SelectedValue as Ages;
selectedTap = selected.DOB;
dayOfYear = (DateTime.Parse(selectedTap, CultureInfo.InvariantCulture).DayOfYear);
//dayOfThisYear.DayOfYear = dayOfYear; //Need to set this date
MessageBox.Show(selectedTap + dayOfYear);
You can create a new DateTime for the current year, then add the appropriate number of days: