Solved

how to convert DATETIME  format to only date in C#

Posted on 2014-04-08
8
4,176 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
 
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Data to display differently-SQL Server 4 19
Jquery autocomplete 10 30
How toselect unique values 3 10
Update in Sql 7 0
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now