Link to home
Start Free TrialLog in
Avatar of codeoxygen
codeoxygen

asked on

how to convert DATETIME format to only date in C#

hi,
    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
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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.
Avatar of codeoxygen
codeoxygen

ASKER

how convert in asp tag ? while binding with eval method
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)

http://www.sqlusa.com/bestpractices/datetimeconversion/
Try using the below tag to format while using Eval

<%# Eval("DateTimeField", "{0:dd-mm--yyyy}") %>
ASKER CERTIFIED SOLUTION
Avatar of Rajiv Lochan Padhi
Rajiv Lochan Padhi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if it is n Code behind page . What is the format
DateField.ToString("dd/MM/yyyy")
textbox.ToString("dd/MM/yyyy")


even after  using this format time value is displaying. Can you help me. in any other option