-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
  • how would I compare stored time with current time to show some text <%if (DateTime.Now > Convert.ToDateTime(Eval("CloseTime","{0:hh:mm:ss tt}"))) { %>

    Shop open

    <% } %>
    – Maqbool Noor Alam Mar 27 '17 at 13:18
  • why don't you compare this in serverside and pass a string value based on condition shop open or shop close – Sriram Mar 28 '17 at 07:06
  • how would i do that? i am accessing the data from sql database table how would i compare it on server side? – Maqbool Noor Alam Mar 28 '17 at 11:45
  • https://www.w3schools.com/sql/func_datediff.asp check this out for datediff in sql – Sriram Mar 28 '17 at 12:34
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.