Formatting numeric values as dates?

  • Thread starter Thread starter Steve Weixel
  • Start date Start date
S

Steve Weixel

I'm having problems getting dates to format the way that I need them to. The
problem is that I'm used to the VB6 way of doing things, with which the
statement Format(37866, "dd MMM yyyy") would yield the string "02 Sep 2003".
If I run the same thing in dotNet, it gives me back the format string, which
isn't very useful.

It *does* work If I convert the value to a date beforehand, but
unfortunately that doesn't help me because I don't know what values are
dates, and what values are other types of numbers at the point where I
actually need to do the formatting.

So the question is, is there a way to format my numeric value as a date
without first converting it into a date? I've been at this for a while and
I'm at a loss...

Thanks in advance,
- Steve
 
Hi Steve,

The bad news is that if <you> don't know whether you've got a date or just
a number, VB.NET <certainly> won't know. And VB.NET doesn't like not knowing
what it's dealing with. Very cagey it is about that sort of thing.

So the question has to be turned around and become how do you determine
what you've got so that you <can> convert into date format?

I'm curious. How do you get to your Format (SomeNumber, "dd MMM yyyy")
without knowing what your dealing with ? And what would your VB6 app do with
the result?

Regards,
Fergus
 
Steve,
I'm try too learn more of the English language.
I somethimes hear the sentences "Blind dates", is that this?
Cor
 
Well, VB6 can figure it out just fine from the format string. <It> knows how
to parse the format string and it <certainly> can recognize a date format
string, and it will recognize that the value is a number that can then be
converted into a date. I know VB.NET isn't VB6, but its supposed to be
BETTER, not worse.

As to your question, I don't literally call Format with some number and a
hard-coded date format string. If I did that then it would be rather obvious
to be that it was a date and I could convert it accordingly. I actually get
a list of values (actually as strings) and a list of format strings from
somewhere and I need to format the numbers according to those format strings
that I was given. Unfortunately, even if I <do> figure out whether or not is
a date, it may be in one of the string formats, or as a number. I was just
trying to simplify my question by skipping the parts about how I get the
values, which are not relevant to the actual question.

Thanks for your help anyway. I'd already decided that it can't do what I
need, I was just seeking other opinions. You never know if someone has
already figured it out.

As an aside, its this kind of stuff that makes VB.NET a pain in the ass. Its
so superior to VB6 in so many ways that it saves gobs of time, but then I
spend weeks on end sorting out the stuff that was trivial in VB6. Without
going into those problems, lets just say I didn't spent <that> much time on
this issue.

- Steve
 
Back
Top