format time

I have a form that displays time as:   10:00:00

I need to remove the seconds

I am using this value to display the time:  <%= (rs_appointment.Fields.Item("startime").Value) %>

This is my SQL:  

SELECT a.activityid, a.firmid, a.acttype, a.actname, a.actnote, a.blobid, a.partylist,a.actdesc,a.dateinitiated, a.processtep, a.lastmodified,a.complete,a.sent_by,a.responsible,a.Schdemailon,   b.caseid, b.alienid,  c.firstnm, c.lastnm, d.mailstr, d.maidenNm, convert(varchar(25), a.dateinitiated, 108) as startime, convert(varchar(25), a.lastmodified, 108) as endtime
FROM dbo.Activities a   left join cases as b on a.caseid =  left join users as c on b.alienid = c.userid  left join users as d on a.responsible = d.userid
WHERE a.ActivityId = MMColParam and a.FirmId = MMColParam2

Help is appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontySenior Web Developer / CEO of Commented:
use the FormatDateTime() function:

<%= ( FormatDateTime( rs_appointment.Fields.Item("startime").Value), 4 ) %>
to do this in the SQL, just limit the length of the varchar

by default style 108 gives hh:mm:ss

to get just hh:mm limit the length to 5 chars

convert(varchar(5), your_data_here ,108)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
Didn't work:  <%= ( FormatDateTime( rs_appointment.Fields.Item("startime").Value), 4 ) %>


Microsoft VBScript compilation  error '800a03ee'

Expected ')'

/BlueDot/Intranet/Calendar/Details.asp, line 309
Response.Write(( FormatDateTime( rs_appointment.Fields.Item("startime").Value), 4 ))
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Big MontySenior Web Developer / CEO of Commented:
to do this in the SQL, just limit the length of the varchar

don't think i agree with this approach, puts unnecessary strain (however small), on the database server, especially when there's a built in function available for use

i had a typo, try:

<%= ( FormatDateTime( rs_appointment.Fields.Item("startime").Value), 4 ) ) %>
strain? yikes, the server would have to be less than a Samsung S3 to be affected by that.

I'm simply offering an alternative that will not strain the server. Note, the convert function is already used (and is necessary), all one is adding is a limit to the length of the varchar.

oh, and by the way, if you are using SQL Server 2012 or later you could (should?) achieve this using FORMAT() instead of convert() e.g.


I have no problem at all formatting at the presentation layer, but it may suit to use the dbms.
AleksAuthor Commented:
Thanks to both !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.