I need to remove time portion of date time or probably have the date in following format in object
form not in the form of string
.
None of the above answers solved my problem on winforms.
the easiest way to reach ONLY date is the simple function in Datetime:
DateTime dt = DateTime.now;
String BirthDate = dt.ToShortDateString();
You will only have date in Birthday string .
I'm surprised no one has mentioned DateTime.Today
var date = DateTime.Today;
// {7/1/2014 12:00:00 AM}
See MSDN
string dt = myCalender.SelectedDate.ToString();
string date = dt.Remove(10);
displayDate.Content = date;
If you take date from calender, with this we also get time. Which is not required all time. Using this we can remove time from date.
You can use this simple code below.
Code: DateTime.Now.ToShortDateString();
Ex. Console.WriteLine(DateTime.Now.ToShortDateString());
You can use format strings to give the output string the format you like.
DateTime dateAndTime = DateTime.Now;
Console.WriteLine(dateAndTime.ToString("dd/MM/yyyy")); // Will give you smth like 25/05/2011
Read more about Custom date and time format strings.
For using by datalist, repeater.. in aspx page:<%# Eval("YourDateString").ToString().Remove(10) %>