Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code is
DateTime FromDate = Convert.ToDateTime(dtFromDate.Value);

it return {4/15/2015 12:00:00 AM} date
but i want only Date "4/15/2015"

How can i do this
plz help me...
Posted

You can't - but it doesn't matter! :laugh:

A DateTime value is just that: a Date and a Time - in fact, it's stored internally as a number of microseconds since an arbitrary point in time, so it physically can't exist as a date output a time component.

But it doesn't matter, because the only time that the Time component is significant is when you try to present the DateTime value to the user by formatting it into a string.
The default conversion includes the full date and time in the current Culture specified format, but you can select any formatting you want: Formatting a DateTime for display - format string description[^]
 
Share this answer
 
C#
var date = FromDate.Date;


Look at this reference
C#
FromDate.ToString("d");
 
Share this answer
 
v2
Comments
Sinisa Hajnal 15-Apr-15 2:27am    
This will still have time component it will only be 00:00:00.00 (or 12AM for those with english culture) - it is how you format it on UI that matters.

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