I want to read the date data type stored in the database, add a day to it and compare it with today’s date. But when I use the AddDays() method, it adds the month instead of the day.
This is my current code:
DateTime date;
DateTime today = DateTime.Now;
private void button1_Click(object sender, EventArgs e)
{
connect.Open();
SqlCommand command = new SqlCommand("Select * from dates", connect);
SqlDataReader reader = command.ExecuteReader();
reader.Read();
date = (DateTime)reader["date"];
DateTime nextDay = date.AddDays(1);
if(nextDay.Date<today.Date)
MessageBox.Show(nextDay.ToString());
connect.Close();
}
I get this message box instead of May 3rd
enter image description here
New contributor
Harun Eminoğlu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2