Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Convert datetime to small date in C#

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-06-2009
Member
 
Join Date: Mar 2009
Posts: 8
Convert datetime to small date in C#
  

I am learning C# in that i want Convert datetime to small date format. I tried to do it but not completed can some one help me ?

Thanks

Reply With Quote
  #2  
Old 09-06-2009
Member
 
Join Date: Oct 2008
Posts: 20
Re: Convert datetime to small date in C#

You can Format time and date by using following code

Code:
using System;  
  
class MainClass {  
  public static void Main() {  
    DateTime dt = DateTime.Now; 
 
    Console.WriteLine("Time is {0:hh:mm tt}", dt); 
  } 
}
Reply With Quote
  #3  
Old 09-06-2009
Member
 
Join Date: Oct 2008
Posts: 73
Re: Convert datetime to small date in C#

To convert a string-based date to a System .DateTime object, you can use the Convert.ToDateTime(String) method or the DateTime.Parse static methodthod.

Eg.

Code:
// Date strings are interpreted according to the current culture.
// If the culture is en-US, this is interpreted as "January 8, 2008",
// but if the user's computer is fr-FR, this is interpreted as "August 1, 2008"
string date = "01/08/2008";
DateTime dt = Convert.ToDateTime(date);            
Console.WriteLine("Year: {0}, Month: {1}, Day: {2}", dt.Year, dt.Month, dt.Day);

// Specify exactly how to interpret the string.
IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);

// Alternate choice: If the string has been input by an end user, you might 
// want to format it according to the current culture:
// IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;
DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal);
Console.WriteLine("Year: {0}, Month: {1}, Day {2}", dt2.Year, dt2.Month, dt2.Day);

/* Output (assuming first culture is en-US and second is fr-FR):
    Year: 2008, Month: 1, Day: 8
    Year: 2008, Month: 8, Day 1
 */
Reply With Quote
  #4  
Old 09-06-2009
Member
 
Join Date: Dec 2008
Posts: 40
Re: Convert datetime to small date in C#

Console.WriteLine("{0}/{1}/{2}", DateTime.Now.ToString("dd"), DateTime.Now.ToString("MM"), DateTime.Now.ToString("yy"))
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Convert datetime to small date in C#"
Thread Thread Starter Forum Replies Last Post
How to convert UTC timestamp value to date and time AsceTic! MS Office Support 2 02-02-2012 06:14 PM
How to convert DateTime to Date and vice versa in c#? Madaleno Software Development 4 05-03-2010 08:35 PM
How to convert string into DateTime Segvoia Software Development 7 05-03-2010 01:55 PM
How to convert date format in postgres Sayam Software Development 3 18-03-2009 11:08 PM
Convert Hex Value to Date from Binary Reg Key RobT Windows Server Help 4 01-04-2005 10:55 AM


All times are GMT +5.5. The time now is 03:52 AM.