date format

  • Thread starter Thread starter TO
  • Start date Start date
T

TO

Hello All,

I have some code that places the numeric value of the
current month (i.e. 12, 11) in a combo box when the
userform is activated. I would like it to show a "0" in
front of the single-digit months (09). I am using the
following code on userform activate.

cmbPer.Value = Format(Date, "mm")

I am using a combo box to give the user the option of
selecting a different month, if necessary.
Thanks
 
Think you are already there. From the immediate window:

dt = dateserial(2004,2,3)
? Format(dt, "mm")
02
 
cmbPer.Value = Format(Date, "mm")-1

this is exactly how I am doing it. My fiscal year starts
in Feb so Oct is actually per 9, but my result is "9"
not "09". Any thoughts?
 
The apparent solution would be to subtract inside the format statement
cmbPer.Value = Format(Month(Date)-1, "mm")

but that won't handle the January.

cmbPer.Value = Format(DateSerial(Year(date),Month(date)-1,1),"mm")

Should be more robust.
 
Excelent, thank you


-----Original Message-----
The apparent solution would be to subtract inside the format statement
cmbPer.Value = Format(Month(Date)-1, "mm")

but that won't handle the January.

cmbPer.Value = Format(DateSerial(Year(date),Month(date)- 1,1),"mm")

Should be more robust.

--
Regards,
Tom Ogilvy






.
 
You can use the DateAdd function to add or subtract a specified time interval
from a date. This will take care of any January issues.

See help on this function
 
That's certainly another way:

dt = DateSerial(2005,1,1)
? DateAdd("m",-1,dt)
12/1/2004
 

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

Back
Top