Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default convert date as text to number

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
--
donwb
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default convert date as text to number

Hi,
Try:
Dim d as date
d=DateValue( <date_string )

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"donbowyer" wrote:

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
--
donwb

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default convert date as text to number

datevalue("dd/mm/yy")

"donbowyer" wrote:

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
--
donwb

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default convert date as text to number

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


"donbowyer" wrote in message
...
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
--
donwb


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default convert date as text to number

Thanks everyone for the responses.
Simply using DateValue did the trick.
--
donwb


"Rick Rothstein (MVP - VB)" wrote:

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


"donbowyer" wrote in message
...
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
--
donwb





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert text date to general number Andrew Excel Discussion (Misc queries) 6 July 19th 07 09:03 AM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
How do I convert a number formated as a date to text in Excel? BrotherNov Excel Discussion (Misc queries) 5 March 2nd 05 03:51 PM
Convert data type of cells to Text,Number,Date and Time Kevin Excel Worksheet Functions 1 December 31st 04 12:57 PM
Convert data of cells to any type: Number, Date&Time, Text Kevin Excel Discussion (Misc queries) 0 December 30th 04 06:55 AM


All times are GMT +1. The time now is 02:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"