Very interesting point Peter. I did a few tests and, based on the
results, think I understand what's going on.
Format("2pm","dddd, d mmmm yyyy, h:mm:ss AMPM")
and
Format("14:00","dddd, d mmmm yyyy, h:mm:ss AMPM")
return
Saturday, 30 December 1899, 2:00:00 p.m.
whereas
Format("2","dddd, d mmmm yyyy, h:mm:ss AMPM")
and
Format("1400","dddd, d mmmm yyyy, h:mm:ss AMPM")
return
Monday, 1 January 1900, 12:00:00 a.m.
and
Saturday, 31 October 1903, 12:00:00 a.m.
respectively.
I'm not quite sure how to explain it succinctly, but I do see
what's going on. It's all based on the "beginning of time" value in
Windows: 12:00:00 a.m. on 30 December 1899. This explains why I was
having problems when I was trying to do some validation on a time
to make sure that it's after the current time; Format is prepending
the value with 30 December 1899, which is _always_ going to be
before Now. I can see some gymnastics are going to be required to
make this work. Still not sure if it's worth the effort for my
current application though. Think I'll probably just stick with my
low-tech solution.
Thanks again for the insight. Another data point for the files.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored. Please
post all follow-ups to the newsgroup.
:
If you do format("2","YYYY") and format("1400","YYYY") you'll find
out what dates /format/ thinks 2 and 1400 are, regardless of what
IsDate does. When you try to apply a time format, format reuturns
the same values as it always does (AFAIK) when you supply a date
but no time.
--
Peter Jamieson
http://tips.pjmsn.me.uk
"Gordon Bentley-Mix" <gordon(dot)bentleymix(at)gmail(dot)com>
wrote in
messageHmm... an interesting possibility...
I wonder how "fault-tolerant" it is - how well it does at
recognising a value as a valid time. For example, what does it
make of something like "2pm"? (Evaluates to "True"...)
Even so I'm still not sure if that will help me with the crap job
that the Format function does, which appears to be possessed and
never quite translates what is input into exactly what is
desired. For example:
Format("14:00","h:mm AMPM")
returns (as expected)
2:00 p.m.
as does
Format("2pm","h:mm AMPM")
but
Format("1400","h:mm AMPM")"
comes back as
12:00 a.m.
as does
Format("2","h:mm AMPM")"
apparently because, according to IsDate (which must be called
implicitly by
Format), "1400" and "2" aren't dates...
So that then leads into the whole User Ed issue - trying to train
the users
on how to enter a value that will actually produce the result
they're looking
for; e.g. enter "14:00" or "2pm" to get "2:00 p.m."
Anyway, thanks for the tip. I can see some possibilities here,
altho I still
think User Ed will be the biggest barrier. I'm not dealing with
the brightest
bulbs in the marquee here. Might be better off with the
comboboxes/option buttons approach...
I'll give it a try and let you know how I get on.
--
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored.
Please post all
follow-ups to the newsgroup.
:
hi Gordon,
IsDate works for both dates and times. For example:
Sub Test()
MsgBox IsDate("21:59")
End Sub
--
Cheers
macropod
[MVP - Microsoft Word]
"Gordon Bentley-Mix" <gordon(dot)bentleymix(at)gmail(dot)com>
wrote in message
G'day!
I've been struggling with this for a long time now (no pun
intended). VBA
provides this wonderfully convenient IsDate function for
checking to see if a
value is a date, but there doesn't seem to be any simple
equivalent "IsTime"
function for checking to see if a value is a time. Does anybody
have a custom
function for doing this?
Also, the Format function does a terrible job of formatting a
times. Any
tips on how to do this?
This has been so problematic in the past that I've had to
implement a workaround by setting up a couple of comboboxes for
selecting the
time - one
for the hour and another for the minutes (in 5 minute
increments) - and option buttons for AM/PM. Surely there must
be a better way... --
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored.
Please post all
follow-ups to the newsgroup.- Hide quoted text -
- Show quoted text -