How to get only the date excluding time in asp.net c#. I want only the date to be given as input to search like eg 3/11/2013
You can use DateTime.Date to get only date part of DateTime object
DateTime dateOnly = date1.Date;
A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).
If you have the Date in string and want to convert it to DateTime object first then you can use DateTime.ParseExact
result = DateTime.ParseExact("3/11/2013", "d/MM/yyyy", CultureInfo.InvariantCulture);
try to use this:
@{
DateTime dd=DateTiem.Now;
string date=dd.toString("dd/MM/yyyy");
}
Now to view just:
@date
DateTime dt = your_Dt.Date;
OR
You can format it into whatever format you want as below:
dt.Tostring("MM/dd/yyyy");
OR
You can convert the valued to shortdate as:
Convert.ToDateTime(your_Dt).ToShortDateString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With