Solved

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

Posted on 2013-06-01
10
963 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
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 11

Expert Comment

by:wrmichael
Comment Utility
Maybe

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

Expert Comment

by:wrmichael
Comment Utility
Here is the msdn article on custom formats

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

Author Comment

by:romsom
Comment Utility
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
 
LVL 22

Assisted Solution

by:Om Prakash
Om Prakash earned 250 total points
Comment Utility
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 250 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Expert Comment

by:clockwatcher
Comment Utility
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
Comment Utility
In classic asp then I think just format(string,"HH:MM") works well.
0
 

Author Closing Comment

by:romsom
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now