Re: Leading 0 when displaying month and date if it is a single digit



"modemgeek" <modemgeek@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A349C1D1-0CA5-45D7-B42B-496D2E6AC10B@xxxxxxxxxxxxxxxx
> I've been looking around and couldn't find a simple way to format the
month
> and date with a leading zero if it is a single digit. Here's what I have:
>
> today = Month(Now()) & "-" & Day(Now()) & "-" & Year(Now())
>
> Result: 1-27-2006
>
> What I want is 01-27-2006.
>
> Thanks in advance.

Will this help?

Dim dtmNow
dtmNow = Now()
Dim today
today = Right("0" & Month(dtmNOW),2) _
& "-" & Right("0" & Day(dtmNOW),2) _
& "-" & Year(dtmNOW)

Of course the MM-DD-YYYY format is not
recommended (where YYYY-MM-DD is).


.



Relevant Pages

  • Re: A question (sort of)
    ... with a zero in front of everything they'll sort in the same order as you've ... But is the number before the slash always a single digit, ... system default format, then the easy option is for your ... I can't seem to get these things to sort. ...
    (microsoft.public.excel.misc)
  • Re: Leading 0 when displaying month and date if it is a single dig
    ... "McKirahan" wrote: ... >> I've been looking around and couldn't find a simple way to format the ... >> and date with a leading zero if it is a single digit. ... > Dim dtmNow ...
    (microsoft.public.windows.server.scripting)
  • date question
    ... I have a string in the format ... Have to to take the date and lpad it with ZERO if its a single digit. ...
    (comp.databases.oracle.misc)
  • Re: negative time values?
    ... Try using this format: ... by default, the second field is for negative numbers, the third for ... zero. ... Yours had negative numbers returning a single digit. ...
    (microsoft.public.excel)
  • Re: date question
    ... I have a string in the format ... Have to to take the date and lpad it with ZERO if its a single digit. ...
    (comp.databases.oracle.misc)

Loading