Click here to Skip to main content
15,567,658 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried below
string dateonly = DateTime.Now.AddDays(-1).ToShortDateString();

if (CIdstatus.WorkedOn == Convert.ToDateTime(dateonly)

but iam getting like this

2014/12/02
Posted

Try:
string dateonly = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");


See here[^] and here[^]

hope this helps.
 
Share this answer
 
Comments
BillWoodruff 3-Dec-14 3:16am    
+5
V. 3-Dec-14 3:20am    
:-)
TheRealSteveJudge 3-Dec-14 3:29am    
5*
V. 3-Dec-14 3:35am    
:-)
Date formtting in C#[^]
Follow up here, this will surely help you out in any kind of format you need.
Post back your queries if any.
Thanks.
 
Share this answer
 
You have to use ToString() to format your string

C#
string dateonly = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");


but if you convert it again into date time "Convert.ToDateTime(dateonly)" then it will be converted into slandered date time format again

Hope this will solve your peoblem
 
Share this answer
 
v3
Comments
V. 3-Dec-14 3:20am    
Actually DateTime does not have a "format". It's just a number (see the Ticks property). It's the representation of the DateTime object that has a certain format. Also use DateTime.TryParseExact for safe conversions. :-)
jayanthik 4-Dec-14 2:28am    
u are right I am getting again 2014/12/02 format pls help me how to avoid dis
Try..
C#
if (CIdstatus.WorkedOn == Convert.ToDateTime(dateonly)
{
string strDate=CIdstatus.WorkedOn.ToString("yyyy-MM-dd");

//and use this strDate string to show wherever you want to show it. 
}
 
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