I have dates and times stored in the database - the data type of DateTime (for example: 17.1.2010 16.23.34 - dd.MM.yyyy hh.mm.ss)
The parameter which I define it has too look ONLY of date ("dd.MM.yyyy"), because I want to get all the values on a specific date and the sum them up.
This is the reason why DateTime.Today doesn`t work, and either it doesn`t DateTime.Today.Date.
So how to declate that it will be correct, that the parameter will look only for date (without time)?
ReplyQuoteMark As AnswerEditDelete
decimal ListaPlačil = 0;
string danesDobiček = @"SELECT SUM(Znesek) FROM Plačilo WHERE DatumPlačila = @danes";
using (SqlCommand cmd = new SqlCommand(danesDobiček, povezava))
{
cmd.Parameters.Add("@danes", SqlDbType.DateTime);
cmd.Parameters["@danes"].Value = DateTime.Today.Date; //This is not the correct parameter, thats why it does not read the database
povezava.Open();
object objListaPlačil = cmd.ExecuteScalar();
if (objListaPlačil != DBNull.Value)
ListaPlačil = Convert.ToDecimal(objListaPlačil);
povezava.Close();
}
return ListaPlačil;