PC Review


Reply
Thread Tools Rate Thread

convert date as text to number

 
 
donbowyer
Guest
Posts: n/a
 
      28th Nov 2007
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 With Quote
 
 
 
 
sebastienm
Guest
Posts: n/a
 
      28th Nov 2007
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

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      28th Nov 2007
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

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      28th Nov 2007
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" <(E-Mail Removed)> wrote in message
news:7D246FB2-ECF1-4C41-8E08-(E-Mail Removed)...
>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 With Quote
 
donbowyer
Guest
Posts: n/a
 
      28th Nov 2007
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" <(E-Mail Removed)> wrote in message
> news:7D246FB2-ECF1-4C41-8E08-(E-Mail Removed)...
> >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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert text to number or date Luis Microsoft Access 7 19th Sep 2009 02:50 PM
Convert text date to general number =?Utf-8?B?QW5kcmV3?= Microsoft Excel Misc 6 19th Jul 2007 09:03 AM
convert text to date/time or number =?Utf-8?B?am9l?= Microsoft Access Getting Started 6 6th Jul 2006 04:11 PM
How do I convert a number formated as a date to text in Excel? =?Utf-8?B?QnJvdGhlck5vdg==?= Microsoft Excel Misc 5 2nd Mar 2005 03:51 PM
Convert a date number to text Eva Shanley Microsoft Excel Worksheet Functions 2 12th Feb 2004 09:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:44 AM.