1

Here em taking input from user and then convert into DateTime when it is print on output screen it show Date and time both but i want to show only Date not time how can i do this??

 //INPUT Console.Write("Pleas Enter Date of Birth: mm-dd-yy: "); Date_Of_Birth = Console.ReadLine(); //Converstion Date_Only = Convert.ToDateTime(Date_Of_Birth); //Printing no ouput Screen. Console.Write(Date_Only);" 

3 Answers 3

1

You can control how DateTime is formatted when printed, by using .ToString("Format") method:

Console.Write(dateOnly.ToString("MM-dd-yy")); 

or use .ToShortDateString() or .ToLongDateString() which will format the date using current culture/language settings.

Sign up to request clarification or add additional context in comments.

Comments

0

Console.Write has its own formatter built in:

 Console.Write("{0:MM-dd-yy}", Date_Only); 

You may also consider using Console.WriteLine rather than Console.Write if you'd like it to place a line feed after the print:

 Console.WriteLine("{0:MM-dd-yy}", Date_Only); 

Comments

0

You can easily convert the datetime object to either date or time

Just replace DateTime.Now with your date object.

Use this for date only

Console.Write(DateTime.Now.ToShortDateString()); 

Use this for time only

Console.Write(DateTime.Now.ToShortDateString()); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.