Reshma
Reshma

Reputation: 1430

how to remove time part

I want remove the time part. While using the given below code getting the out but like given : 4/27/2015 12:00:00 AM I want remove the 12:00:00 AM. I tried some methods. but it is not working. Code:

DateTime start = Convert.ToDateTime(txtStart.Text);
DateTime end = Convert.ToDateTime(txtEnd.Text);
var date1 = start .Date;
var date2 = end .Date;

Upvotes: 0

Views: 98

Answers (4)

Burning Crystals
Burning Crystals

Reputation: 1167

You can format the date.

String.Format("{0:M/d/yyyy}", start); // output: 4/27/2015
String.Format("{0:M/d/yyyy}", end); // output: 4/27/2015

Upvotes: 0

Midhun Mundayadan
Midhun Mundayadan

Reputation: 3182

String test = DateTime.Now.ToString("dd.MM.yyy");

else

DateTime.Now.ToShortDateString ()

Upvotes: 1

akhil kumar
akhil kumar

Reputation: 1618

try using format function and format to custom date format.

DateTime start = Convert.ToDateTime(txtStart.Text);
DateTime end = Convert.ToDateTime(txtEnd.Text);
var date1 = format(start.Date,"dd/MM/yyyy");
var date2 = format(end.Date,"dd/MM/yyyy");

Now tested and is working fine.use the format which u want.i assume u need "MM/dd/yyyy".

Upvotes: 1

Chetan Bodke
Chetan Bodke

Reputation: 523

You can Following Code , the ToDateShortString() will Produce Date:

DateTime start = Convert.ToDateTime(txtStart.Text);
DateTime end = Convert.ToDateTime(txtEnd.Text);

var date1 = start.ToShortDateString();
var date2 = end.ToShortDateString();

Upvotes: 1

Related Questions