Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

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 = b.id  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.
SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Didn't work:  <%= ( FormatDateTime( rs_appointment.Fields.Item("startime").Value), 4 ) %>

Error:  

Microsoft VBScript compilation  error '800a03ee'

Expected ')'

/BlueDot/Intranet/Calendar/Details.asp, line 309
Response.Write(( FormatDateTime( rs_appointment.Fields.Item("startime").Value), 4 ))
------------------------------------------------------------------------------^
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.

FORMAT([YourTimeColumn],'mm:ss')

I have no problem at all formatting at the presentation layer, but it may suit to use the dbms.
Avatar of Aleks

ASKER

Thanks to both !