CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2005
    Posts
    5

    Date Formatting Problem

    Hi,

    I am trying to format the date display but i find problem while formatting the year part

    DateTime dt2 = new DateTime(03,02,01);

    Console.WriteLine(dt2.ToString("dd-MMM-yyyy"));


    Output is 01-Feb-0003

    Required output is 01-Feb-2003

    Note:- The input date arguments comes from another logic with only in 'yy' format i need to convert it to 'yyyy' format

    Thanks in advance for the help

    Anand

  2. #2
    Join Date
    May 2007
    Posts
    437

    Re: Date Formatting Problem

    generally

    The DateTime value type represents dates and times with values ranging from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.)
    so implement at your function to convert 03 to 2003, or may be 1903

    ashu
    always use code tag

  3. #3
    Join Date
    Aug 2007
    Posts
    2

    Thumbs up Re: Date Formatting Problem

    I think u can use String.Format()

  4. #4
    Join Date
    Nov 2004
    Posts
    105

    Re: Date Formatting Problem

    The format what you are using is correct.
    Try This

    DateTime dt = DateTime.Now;
    string stemp=dt.ToString("MMMM dd yyyy");

    Regards
    Ravi.Battula

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured