date formatting

T

the other john

I have a client that wants a time field to resolve to 7:00 PM rather
than 7:00:00 PM (wants the seconds gone). vbLongTime provides the
later but vbShortTime produces a 24 hour version or 19:00. Any
suggestions?

Thanks!
 
A

Aaron Bertrand [SQL Server MVP]

This is a display issue, not a storage issue. It is relatively trivial to
format the output how you want when you present it. But assuming that the
data is stored in some string-dependent format is a mistake; this is not how
dates are actually stored.
 
T

the other john

I have stored the datetime value in the database in it's full format.
This is a display problem The client just wants the seconds gone.
7:00 PM rather than 7:00:00 PM. I don't see a solution in the prior
information either, sorry.
 
C

Chris Hohmann

the other john said:
I have stored the datetime value in the database in it's full format.
This is a display problem The client just wants the seconds gone.
7:00 PM rather than 7:00:00 PM. I don't see a solution in the prior
information either, sorry.
Did you try the "Replicating VB's Format() function" solution on the link
Bob provided?

The format string for your particular situation would be "h:mm AMPM".

-HTH
Chris Hohmann
 
B

Bob Barrows [MVP]

the said:
I have stored the datetime value in the database in it's full format.

No you have not. You did not tell us what database you are using, but I can
say with a good degree of certainty that your database is not storing
datetimes with any format. If you are interested in the details of how your
database stores the datetimes, I suggest reading the documentation for your
database.
This is a display problem

Yes, we know. It is up to the client application to apply formatting to
datetimes.
The client just wants the seconds gone.
7:00 PM rather than 7:00:00 PM. I don't see a solution in the prior
information either, sorry.

Umm, forgive me, but you're expected to be able to read and interpret what
was presented. For example, the article I cited contained several examples
of using vbscript to format dates. Like this:
*********************************
YYYYMMDD

(This is the preferred date format for passing dates to a SQL Server
database, as it eliminates the need to worry about regional settings. See
Article #2260 for more information.)

<%
response.write YEAR(Date()) & _
Pd(Month(date()),2) & _
Pd(DAY(date()),2)
%>

**********************************
As you can see, it's simply a matter of using builtin vbscript date
functions (year(), month() and day()) to extract the specific information
from the date and concatenate the bits together in the desired format. A
quick look at the vbscript documentation would have revealed the existence
of similar functions to extract time-related information from a date. I did
not expect to have to spell it out for you, but here you go:

dim d, h, suffix
d=<datetime from database>
h=hour(d)
if h = 0 then
h = 12
suffix = " AM"
elseif h < 13 then
suffix = " AM"
else
suffix = " PM"
h = h - 12
end if
response.write h & ":" & minute(d) & suffix

Bob Barrows
 
T

the other john

sorry you had to spell it out. I go to newsgroups to learn and I've
learned something...so why do I feel I did something wrong? geez.
 
B

Bob Barrows [MVP]

the said:
sorry you had to spell it out. I go to newsgroups to learn and I've
learned something...so why do I feel I did something wrong? geez.

Maybe because you didn't take the opportunity to learn that was presented to
you.
There's no better way to learn than by looking at examples, going to the
documentation to figure out how the examples work, looking at the "see also"
links to see ways of expanding on the examples to apply them to your
situation, etc.

Is the problem that you don't have the documentation? It's not uncommon with
vbscript. Here's a link to enable you to download the scripting sdk:
http://www.microsoft.com/downloads/...48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,837
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top