Solved

how to convert DATETIME  format to only date in C#

Posted on 2014-04-08
8
4,420 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

825 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