?
Solved

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

Posted on 2013-06-01
10
Medium Priority
?
1,054 Views
Last Modified: 2013-06-01
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
Comment
Question by:romsom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 11

Expert Comment

by:wrmichael
ID: 39213668
Maybe

rs("TimeCompleted").toString("hh:mm")
0
 
LVL 11

Expert Comment

by:wrmichael
ID: 39213669
Here is the msdn article on custom formats

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
0
 

Author Comment

by:romsom
ID: 39213702
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Assisted Solution

by:Om Prakash
Om Prakash earned 1000 total points
ID: 39213733
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
 
LVL 25

Accepted Solution

by:
clockwatcher earned 1000 total points
ID: 39213754
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
 
LVL 25

Expert Comment

by:clockwatcher
ID: 39213756
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
 
LVL 11

Expert Comment

by:wrmichael
ID: 39213779
In classic asp then I think just format(string,"HH:MM") works well.
0
 

Author Closing Comment

by:romsom
ID: 39213781
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
 
LVL 11

Expert Comment

by:wrmichael
ID: 39213783
See this for vb6 style format that should work with classic asp

http://www.vb6.us/tutorials/formating-dates-and-times-vb6
0
 
LVL 11

Expert Comment

by:wrmichael
ID: 39213787
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question