We help IT Professionals succeed at work.

Display Time from SQL Server Database

baxtalo
baxtalo asked
on
Hi Experts,
My web pages are written in Classic ASP and I submit time to SQL Server database in the following format:
15:37
On my web page the submission is displayed like this:
1/1/1900 15:37:00 PM
because the field is set to 'datetime'.
How could I modify <%=rs("MyTime")%> in order to have it on my page displayed only 15:37
Thank you for your help.
Comment
Watch Question

In your SQL querry change the column Mytime as follows

convert(varchar(10),Mytime,101) + ' ' + convert(varchar(5),Mytime ,114) as Mytime
Top Expert 2011

Commented:
Use this:

<%= FormatDateTime(yourdatetime,4) %>

Author

Commented:
santhimurthyd, when I used your suggestion the time was returned the following way:
01/01/1900 11:35
I would like to see 11:35 instead. How could I get rid of 01/01/1900?

sammySeltzer, your suggestion returned 00:00 instead of 11:35
Use this

convert(varchar(5),Mytime ,114) as Mytime
Top Expert 2011
Commented:
are you sure you are doing it correctly?

See screenshot for what my test returned.

Then the code:

<%
Response.Write FormatDateTime(time, 4)
%>

or

<%
Response.Write FormatDateTime(now(), 4)
%>

timeformat.JPG

Author

Commented:
Thank you very much both of you.
santhimurthyd, your solution returned the expected results.
sammySeltzer, I just don't know how to customize your solution to my needs. My column name is 'MyTime', and I'm not sure how I could replace it in the Response.Write you suggested.