convert date as text to number

D

donbowyer

I want to subtract one date from another to obtain days between.
The format of the dates is dd/mm/yy
This works fine if both dates are <<numbers>>.
However, one date comes from a UserForm TextBox and is <<Text>>.
I have used successfully the "PasteMultiply" by 1 trick to convert text that
looks like a NUMBER to a true number,
BUT it doesn't seem to work with text that looks like a DATE.
Help please
 
R

Rick Rothstein \(MVP - VB\)

You can use the DateValue function as shown in the other responses or you
can just return the value from the TextBox wrapped in the CDate function...

ReturnValue = CDate(TextBox1.Text)

However, since you are taking your input as a typed in String value, you may
want to test it with the IsDate function (for either the CDate or DateValue
method of conversion) first to make sure you really have a date-shape String
value.

Rick
 

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

Top