-1

in database it is stored like this: data type: datetime column Name:OpenTime data: 01/01/00 08:00:00 AM

when I fetch the data on aspx page its showing like above

i want it to show only time no date in this format 08:00 AM what code should i add to the below code

3 Answers3

1

Try string formating in Eval

There are several ways to format the date.

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

in your case

<%#Eval("OpenTime", "{0:HH:mm:ss}") %>
Sriram
  • 739
  • 7
  • 18
0

You can try the query to fetch time only like this select cast(ColumnName as time) [time] from yourTableName.

  • Depending on the database engine, that might return the correct time with the current date. If you are going to do this in the query itself, use a function that returns a string. – Dan Bracuk Mar 27 '17 at 12:59
0

DateTime dt = new DateTime(); string dtDisplay = string.Empty;

dt=DateTime.Now; dtDisplay = dt.ToString("hh:mm tt");

then you can display the dtDisplay value in the aspx page.