Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 23-Nov-12 5:08am
Edited 23-Nov-12 6:08am
ridoy51.7K
v2
Comments
Krunal R at 23-Nov-12 11:10am
   
what are you getting as output, show me..

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
sumit kausalye at 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 at 23-Nov-12 11:49am
   
Solution is suggesting u to use "MM/dd/yyyy". Upper case MM.
RaisKazi at 23-Nov-12 11:48am
   
Correct, My 5.
ridoy at 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)

  Print Answers RSS
0 OriginalGriff 398
1 Sergey Alexandrovich Kryukov 320
2 Uma Shankar Patel 80
3 CB Sharma 79
4 PhilLenoir 70
0 Sergey Alexandrovich Kryukov 6,532
1 OriginalGriff 5,976
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,550


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100