?
Solved

how to convert DATETIME  format to only date in C#

Posted on 2014-04-08
8
Medium Priority
?
5,092 Views
Last Modified: 2014-04-29
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
Comment
Question by:codeoxygen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39985733
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
 

Author Comment

by:codeoxygen
ID: 39985743
how convert in asp tag ? while binding with eval method
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 39985776
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39985850
Try using the below tag to format while using Eval

<%# Eval("DateTimeField", "{0:dd-mm--yyyy}") %>
0
 
LVL 1

Accepted Solution

by:
Rajiv Lochan Padhi earned 1500 total points
ID: 39985878
<%# Convert.ToDateTime(Eval("Date")).ToString("dd/MM/yyyy") %>

or

<%# Eval("Date","{0:dd/MM/yyyy}") %>
0
 

Author Comment

by:codeoxygen
ID: 39991259
if it is n Code behind page . What is the format
0
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39991262
DateField.ToString("dd/MM/yyyy")
0
 

Author Comment

by:codeoxygen
ID: 40029266
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question