Hallo everyone.

I want to set the day to the validDay.
e.g if valid day is 25 then the day must be 25 on DateTime.

string validDay_str = reader["validation"].ToString();
        int validDay = Int32.Parse(validDay_str);
string start_str = reader["start"].ToString();
        DateTime start = DateTime.Parse(start_str);

start.Day = validDay;

with this code I get an error, "Property or indexer 'System.DateTime.Day' cannot be assigned to -- it is read only"

I cannot use

start = start.AddDays(validdaye);

because then it will add 25 to the existing day.

it is quite simple u can do this in folllowing manner:

DateTime start=DateTime start = DateTime.Parse(start_str);
now u want only to set day to validday u should make a separate method like this
private DateTime setDay(int DayToSet,DateTime DateToBeSet)
{

return new DateTime(DateToBeSet.Year,DateToBeSet.Month,DayToSet);

}

then u would call:
start=setDay(validday,start);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.