c# convert DateTime to Boolean

Status
Not open for further replies.

dann11

Full Member level 3
Joined
Oct 22, 2015
Messages
166
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,742
Hi! I am trying to use time difference and date as my condition to update my counter value. but I certainly get an error of "Invalid cast from 'DateTime' to 'Boolean'." Please help what is the proper conversion.

I have my as below:

Code:
 public void counterUpdate()
		{
			
			
			MySqlConnection conn = new MySqlConnection();
			
			conn = new MySqlConnection(cs);
			
			
			DateTime t1 = DateTime.Now;
			DateTime t2 = resettingTime.valueOfResetTime();
			
			TimeSpan diff = t1 - t2;
			
			if((Convert.ToUInt64(diff.Hours) > 0) && (Convert.ToBoolean(date)))
			{
			
					
			//UpdateValue
			{
				string stmmbc = "UPDATE `database` SET `Actual` = '"+Counter.getActual().ToString()+"' Where `Date`='"+date.ToString(format)+"'";
								
				MySqlCommand cmd = new MySqlCommand(stmmbc, conn);
				cmd.Connection.Open();
			try
			{
				cmd.ExecuteNonQuery();
												         
			}
			
			catch(MySqlException ex)
				{
					MessageBox.Show(ex.ToString());
						 
		  		}
			
			
				}
			}
                    else

                     {
                      //do nothing
                      }
}
 

What is Convert.ToBoolean(date) expected to mean? Seems useless.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…