Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How To Seperate on get only date from datetime format like this 04/12/2013 12:00:00 AM
only date means i want only date as 04/12/2013
Posted
Comments
BillWoodruff 5-Dec-13 0:10am    
You need to do some basic research on the methods in the DateTime Class which make solving problems like this simple.
Ganesh KP 5-Dec-13 0:21am    
Where you want to do, using WPF in XAML or in code behind, give us complete question to answer.

A lot of methods are there

in C# one simple method is

C#
dt.ToShortDateString();


where dt is ur DateTime variable
 
Share this answer
 
v2
Try Something Like that
C#
var dateAndTime = DateTime.Now;
var date = dateAndTime.Date;
 

// or 
var dateAndTime = DateTime.Now;
Console.WriteLine(dateAndTime.ToString("dd/MM/yyyy"));
// or
var dateOnlyString = dateTimeNow.ToShortDateString; //Return 00/00/0000
//or
DateTime.Now.ToString("dd-MM-yyyy");

For More detail see this C# DateTime Format
 
Share this answer
 
v2
try something like this


DateTime date1 = DateTime.Now;
Console.WriteLine(date1.ToString());
DateTime dateOnly = date1.Date;
Console.WriteLine(dateOnly.ToString("d"));

hope it works :)
 
Share this answer
 
You can also use substring fuction to cut off unnecessary part of string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900