C# String function

I am converting a datetime to just a date, that is also in a different order. I have been away from programming for a bit and I have it working properly easily enough using substring, but was wondering if there was maybe an easier way of doing it.

Format coming in -  2011-11-01 00:00:00
Format needed -  11/01/2011

Thanks
Lance
 
lva6600311Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_davisCommented:
yourDateTimeObject.ToString("MM/dd/yyyy");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
keyuCommented:
using System;  // has all the date/time stuff class myApp{  public static void Main()  {    DateTime CurrTime = DateTime.Now;     Console.WriteLine("DateTime display listing specifier and result:\n");     Console.WriteLine("d = {0:d}", CurrTime );  // Short date mm/dd/yyyy    Console.WriteLine("D = {0:D}", CurrTime );  // Long date day, month dd, yyyy    Console.WriteLine("f = {0:f}", CurrTime );  // Full date/short time day, month dd, yyyy hh:mm    Console.WriteLine("F = {0:F}", CurrTime );  // Full date/full time day, month dd, yyyy HH:mm:ss AM/PM    Console.WriteLine("g = {0:g}", CurrTime );  // Short date/short time mm/dd/yyyy HH:mm    Console.WriteLine("G = {0:G}", CurrTime );  // Short date/long time mm/dd/yyyy hh:mm:ss    Console.WriteLine("M = {0:M}", CurrTime );  // Month dd    Console.WriteLine("R = {0:R}", CurrTime );  // ddd Month yyyy hh:mm:ss GMT    Console.WriteLine("s = {0:s}", CurrTime );  // yyyy-mm-dd hh:mm:ss  can be sorted!    Console.WriteLine("t = {0:t}", CurrTime );  // Short time hh:mm AM/PM    Console.WriteLine("T = {0:T}", CurrTime );  // Long time hh:mm:ss AM/PM    Console.WriteLine("u = {0:u}", CurrTime );  // yyyy-mm-dd hh:mm:ss  universal/sortable    Console.WriteLine("U = {0:U}", CurrTime );  // day, month dd, yyyy hh:mm:ss AM/PM    Console.WriteLine("Y = {0:Y}", CurrTime );  // Month, yyyy    Console.WriteLine();    Console.WriteLine("DateTime.Month     = " + CurrTime.Month);      // number of month    Console.WriteLine("DateTime.DayOfWeek = " + CurrTime.DayOfWeek);  // full name of day    Console.WriteLine("DateTime.TimeOfDay = " + CurrTime.TimeOfDay);  // 24 hour time     // number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am    // useful for time-elapsed measurements    Console.WriteLine("DateTime.Ticks     = " + CurrTime.Ticks);     Console.Read();  // wait  }} // retrieve and format date/time data
// tested with VCS.NET 2003

using System;  // has all the date/time stuff
 
class myApp
{
  public static void Main()
  {
    DateTime CurrTime = DateTime.Now;
 
    Console.WriteLine("DateTime display listing specifier and result:\n");

    Console.WriteLine("d = {0:d}", CurrTime );  // Short date mm/dd/yyyy
    Console.WriteLine("D = {0:D}", CurrTime );  // Long date day, month dd, yyyy
    Console.WriteLine("f = {0:f}", CurrTime );  // Full date/short time day, month dd, yyyy hh:mm
    Console.WriteLine("F = {0:F}", CurrTime );  // Full date/full time day, month dd, yyyy HH:mm:ss AM/PM
    Console.WriteLine("g = {0:g}", CurrTime );  // Short date/short time mm/dd/yyyy HH:mm
    Console.WriteLine("G = {0:G}", CurrTime );  // Short date/long time mm/dd/yyyy hh:mm:ss
    Console.WriteLine("M = {0:M}", CurrTime );  // Month dd
    Console.WriteLine("R = {0:R}", CurrTime );  // ddd Month yyyy hh:mm:ss GMT
    Console.WriteLine("s = {0:s}", CurrTime );  // yyyy-mm-dd hh:mm:ss  can be sorted!
    Console.WriteLine("t = {0:t}", CurrTime );  // Short time hh:mm AM/PM
    Console.WriteLine("T = {0:T}", CurrTime );  // Long time hh:mm:ss AM/PM
    Console.WriteLine("u = {0:u}", CurrTime );  // yyyy-mm-dd hh:mm:ss  universal/sortable
    Console.WriteLine("U = {0:U}", CurrTime );  // day, month dd, yyyy hh:mm:ss AM/PM
    Console.WriteLine("Y = {0:Y}", CurrTime );  // Month, yyyy
    Console.WriteLine();
    Console.WriteLine("DateTime.Month     = " + CurrTime.Month);      // number of month
    Console.WriteLine("DateTime.DayOfWeek = " + CurrTime.DayOfWeek);  // full name of day
    Console.WriteLine("DateTime.TimeOfDay = " + CurrTime.TimeOfDay);  // 24 hour time
   
    // number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am
    // useful for time-elapsed measurements
    Console.WriteLine("DateTime.Ticks     = " + CurrTime.Ticks);

    Console.Read();  // wait
  }
}


REf.L:ink:  http://www.daniweb.com/software-development/csharp/code/216441
0
keyuCommented:
using System;  // has all the date/time stuff
 
class myApp
{
  public static void Main()
  {
    DateTime CurrTime = DateTime.Now;
 
    Console.WriteLine("DateTime display listing specifier and result:\n");

    Console.WriteLine("d = {0:d}", CurrTime );  // Short date mm/dd/yyyy
    Console.WriteLine("D = {0:D}", CurrTime );  // Long date day, month dd, yyyy
    Console.WriteLine("f = {0:f}", CurrTime );  // Full date/short time day, month dd, yyyy hh:mm
    Console.WriteLine("F = {0:F}", CurrTime );  // Full date/full time day, month dd, yyyy HH:mm:ss AM/PM
    Console.WriteLine("g = {0:g}", CurrTime );  // Short date/short time mm/dd/yyyy HH:mm
    Console.WriteLine("G = {0:G}", CurrTime );  // Short date/long time mm/dd/yyyy hh:mm:ss
    Console.WriteLine("M = {0:M}", CurrTime );  // Month dd
    Console.WriteLine("R = {0:R}", CurrTime );  // ddd Month yyyy hh:mm:ss GMT
    Console.WriteLine("s = {0:s}", CurrTime );  // yyyy-mm-dd hh:mm:ss  can be sorted!
    Console.WriteLine("t = {0:t}", CurrTime );  // Short time hh:mm AM/PM
    Console.WriteLine("T = {0:T}", CurrTime );  // Long time hh:mm:ss AM/PM
    Console.WriteLine("u = {0:u}", CurrTime );  // yyyy-mm-dd hh:mm:ss  universal/sortable
    Console.WriteLine("U = {0:U}", CurrTime );  // day, month dd, yyyy hh:mm:ss AM/PM
    Console.WriteLine("Y = {0:Y}", CurrTime );  // Month, yyyy
    Console.WriteLine();
    Console.WriteLine("DateTime.Month     = " + CurrTime.Month);      // number of month
    Console.WriteLine("DateTime.DayOfWeek = " + CurrTime.DayOfWeek);  // full name of day
    Console.WriteLine("DateTime.TimeOfDay = " + CurrTime.TimeOfDay);  // 24 hour time
   
    // number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am
    // useful for time-elapsed measurements
    Console.WriteLine("DateTime.Ticks     = " + CurrTime.Ticks);

    Console.Read();  // wait
  }
}


REf.L:ink:  http://www.daniweb.com/software-development/csharp/code/216441
0
lva6600311Author Commented:
Thanks. Thought it would be pretty easy to manipulate.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.