• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5640
  • Last Modified:

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
0
codeoxygen
Asked:
codeoxygen
1 Solution
 
AndyAinscowCommented:
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.
0
 
codeoxygenAuthor Commented:
how convert in asp tag ? while binding with eval method
0
 
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)

http://www.sqlusa.com/bestpractices/datetimeconversion/
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
jayakrishnabhCommented:
Try using the below tag to format while using Eval

<%# Eval("DateTimeField", "{0:dd-mm--yyyy}") %>
0
 
Rajiv Lochan PadhiCommented:
<%# Convert.ToDateTime(Eval("Date")).ToString("dd/MM/yyyy") %>

or

<%# Eval("Date","{0:dd/MM/yyyy}") %>
0
 
codeoxygenAuthor Commented:
if it is n Code behind page . What is the format
0
 
jayakrishnabhCommented:
DateField.ToString("dd/MM/yyyy")
0
 
codeoxygenAuthor Commented:
textbox.ToString("dd/MM/yyyy")


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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now