Change Date format 12/26/2015 to 12-26-2015 vb6

isnoend2001
isnoend2001 used Ask the Experts™
on
This does not work
FutureYr = Format(FutureYr, "mm-dd-yyyy")
It does not change the format.
How to do this ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Hi,

pls try

FutureYr = Format(DateValue(FutureYr), "mm-dd-yyyy")

Open in new window

Regards
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
It depends on what is FutureYr? How you have declared it in your original code? Is it just a variable or a control? Are you assigning the FutureYr back to a cell on the sheet? So many questions and not sure you will get your logical answer unless you provide these details.

Otherwise as such nothing is wrong with statement.

Author

Commented:
Sorry about the late reply,had to run an unexpected errand
Dim FutureYr As Date
this did not fix it:
FutureYr = Format(DateValue(FutureYr), "mm-dd-yyyy")
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
Use MsgBox FutureYr or Debug.Print FutureYr to see the value in immediate window. Do you see it in desired format?

How do you know that you don't get it in right format? What do you do next with FutureYr, do you place its value on the sheet or what?

If you are placing the value of FutureYr on the sheet, that might not work as sheet's default date separator will take over.

Author

Commented:
Have already used debug, don't know why vb ignores the format.
Have overcame the issue by converting the date to a string using cstr

Author

Commented:
Thanks
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
Smart! Glad your issue has been resolved.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial