0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jellybeannn
0

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);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.