how to convert DATETIME format to only date in C#

    I am pulling data from the database, one of the column is date. even though time values is not saved in the table. its displaying default time in grid. I am using Eval() method for assigning value . Can any one help me. Thanks in advance
Who is Participating?
Rajiv Lochan PadhiConnect With a Mentor Software ProgrammerCommented:
<%# Convert.ToDateTime(Eval("Date")).ToString("dd/MM/yyyy") %>


<%# Eval("Date","{0:dd/MM/yyyy}") %>
AndyAinscowFreelance programmer / ConsultantCommented:
A couple of possible ways for you to consider:
Set a format for the grid cell that is date only.
Convert to a string and display that rather than a datetime.
codeoxygenAuthor Commented:
how convert in asp tag ? while binding with eval method
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Tapan PattanaikSenior EngineerCommented:
Hi codeoxygen,

one suggestion from my side, please retrive only date part from the database.So, it will
display only the date in the grid and it will not display date and default time in grid.

SELECT convert(datetime, '10/23/2016', 101) -- mm/dd/yyyy

for more time format details, please check the link. (you have to in database labels)
Try using the below tag to format while using Eval

<%# Eval("DateTimeField", "{0:dd-mm--yyyy}") %>
codeoxygenAuthor Commented:
if it is n Code behind page . What is the format
codeoxygenAuthor Commented:

even after  using this format time value is displaying. Can you help me. in any other option
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.