Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.11/5 (3 votes)
See more:
Hi all

I write some code to check that now date is tomorrow :

C#
string re_dat = string.Empty;
       re_dat = SDKClass.Selct_Date_now(); // return today date from database

     bool date_now = DateTime.Parse(re_dat).AddDays(1);

      if(date_now)
      {
          Response.Write("tomorrow");
      }


but i have following error :
Cannot implicitly convert type 'DateTime' to 'bool'

Thanks a lot.
Posted

C#
DateTime toCheck = DateTime.Parse(re_dat).Date;
if (DateTime.Now.AddDays(1).Date == toCheck)
   {
   ...
   }
 
Share this answer
 
Comments
bernova 12-Jun-15 8:24am    
Thanks for your response.
But you say that if DateTime.Now.AddDays(1).Date equal to date that return from database , so today is tomorrow ?!!!
OriginalGriff 12-Jun-15 8:32am    
DateTime.Now - this exact moment.
(This exact moment).AddDays(1) - this exact time but tomorrow
(this exact time but tomorrow).Date - Midnight, start of tomorrow (strips off the time element)

So
if (DateTime.Now.AddDays(1).Date == toCheck)
matches if and only if toCheck is also midnight, start of tomorrow.
bernova 12-Jun-15 16:02pm    
thanks , but this condition don't fire.

if (DateTime.Now.AddDays(1) == date_now)
{
SDKClass.Update_date(DateTime.Now.ToShortDateString());
int re_t = Convert.ToInt32(select_today_view);
int re_yes = Convert.ToInt32(select_yesterday_View);
int re_s = re_t + re_yes;
SDKClass.Update_yesterday_View(Convert.ToString(re_s));

SDKClass.Update_today_View("1");
}
OriginalGriff 12-Jun-15 16:18pm    
Now compare what you have as code to what I had as code, and the description I typed seven hours ago... :sigh:
bernova 12-Jun-15 16:46pm    
sorry My internet connection has been lost.
Hi
C#
var yourDate = DateTime.Now; // provide your date;
           if (yourDate == DateTime.Now.AddDays(1))
           {
              // this is tomarrow
           }


Thanks
Bimal
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900