Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1156
  • Last Modified:

Is there a way to format the vbLongTime without displaying the seconds?

The code below returns the time from SQL Server database.

<%=FormatDateTime(rs("TimeCompleted"),vbLongTime)%>

I get: 12:47:00 PM

I would like: 12:47 PM

Thanks for your help.
0
romsom
Asked:
romsom
  • 5
  • 2
  • 2
  • +1
2 Solutions
 
Wayne MichaelSenior Software DeveloperCommented:
Maybe

rs("TimeCompleted").toString("hh:mm")
0
 
Wayne MichaelSenior Software DeveloperCommented:
Here is the msdn article on custom formats

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
0
 
romsomAuthor Commented:
I've tried it and this is the error I get:
Object doesn't support this property or method: 'toString'
Maybe because my page is written in Classic ASP
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Om PrakashCommented:
you can use vbShortTime but it will give time in 24 hour format

one crude way is to trim :00 if seconds is always 00 in your database
replace(FormatDateTime(rs("TimeCompleted"),vbLongTime),":00","")
0
 
clockwatcherCommented:
I don't think you'd want to do a replace that way as 7:00:00 PM might look a bit odd.  It's no problem to trim it out though:
<script language="vbscript" runat="server">

function MyTimeFormat(v)
 
   dim c
    v = FormatDateTime(v, vbLongTime)
    c = instrrev(formatdatetime(v,vbLongTime), ":")
    if c > 0 then
        MyTimeFormat = left(v,c-1) & mid(v,c + 3)

    else
        MyTimeFormat = v
    end if
end function
</script>

<%= MyTimeFormat(rs("TimeCompleted")) %>

Open in new window


Or use a regexp:
function MyTimeFormat(v)
    dim re
    v = FormatDateTime(v, vbLongTime)
    set re = new RegExp
    re.pattern = "(\d+:\d+):\d+"
    MyTimeFormat1 = re.replace(v, "$1")
end function

Open in new window

0
 
clockwatcherCommented:
I suppose if you included the trailing space in the replace, you'd be fine:

replace(FormatDateTime(rs("TimeCompleted"),vbLongTime),":00 "," ")

But it would only work if you always had 00 seconds in your field as om_prakash_p mentioned.
0
 
Wayne MichaelSenior Software DeveloperCommented:
In classic asp then I think just format(string,"HH:MM") works well.
0
 
romsomAuthor Commented:
Both methods work for me, thank you very much for your help.
The seconds are always 00, so I don't need to display them
0
 
Wayne MichaelSenior Software DeveloperCommented:
See this for vb6 style format that should work with classic asp

http://www.vb6.us/tutorials/formating-dates-and-times-vb6
0
 
Wayne MichaelSenior Software DeveloperCommented:
0
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now