Solved

how to convert DATETIME  format to only date in C#

Posted on 2014-04-08
8
4,723 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

739 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