Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DateTime date = DateTime.Now;
            string str="";
            date =Convert.ToDateTime(dtl.Rows[0]["createddate"].ToString());
            str = date.ToString("mm/dd/yyyy");


            DateTime datenow = DateTime.Now;
            string strnow="";
            strnow = datenow.ToString("mm/dd/yyyy");
            if (str != strnow)
            {

            }


//this gives me wrong month for both string variable why? and what is solution for that?
Posted
Updated 23-Nov-12 6:08am
v2
Comments
[no name] 23-Nov-12 11:10am    
what are you getting as output, show me..

1 solution

In the string conversion of a date, lower case mm returns the minutes. For months, you must use upper case, MM. Your format string should therefore be "MM/dd/yyyy".

Happens to me, too.
 
Share this answer
 
v2
Comments
sumit kausalye 23-Nov-12 11:41am    
no even if i put lower case mm still its gives me wrong output..
only for mm,yyyy and dd is given me correct output,mm is wrong
RaisKazi 23-Nov-12 11:49am    
Solution is suggesting u to use "MM/dd/yyyy". Upper case MM.
RaisKazi 23-Nov-12 11:48am    
Correct, My 5.
ridoy 23-Nov-12 12:21pm    
+5

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