Sponsored Ad

Saturday, May 15, 2010

How to Display Date in Reverse Format in C#

Sometimes we need to play with date and we need to display date in reverse format. So I am here with a C# code research.

This example is for today’s date while you can change this code to display any date in reverse format.

Source code  Display Date in Reverse Format in C#:

private string ReversedDateString( )
        {
            string reversedDate;

            // year component
            reversedDate = DateTime.Now.Year.ToString().Substring( 2, 2 );

            // month component
            reversedDate += DateTime.Now.Month.ToString( "00" );

            // day component
            reversedDate += DateTime.Now.Day.ToString( "00" );

            return reversedDate;
        }

2 comments:

  1. The above program is not working please check out

    ReplyDelete
  2. Hi,

    This is working fine.

    like for todays date 7/6/2011
    it will print 110607

    while if you want year in full format you can the below line

    reversedDate = DateTime.Now.Year.ToString().Substring( 2, 2 );

    to

    reversedDate = DateTime.Now.Year.ToString();

    it will print

    20110607

    ReplyDelete

Sponsored Ad

Development Updates