473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Simple Conversion from String to Date

VS2005 in VB.NET

I have 2 simple textboxes (Textbox1, Textbox2) and they both have dates.

Textbox1=12/31/2006
Textbox2=12/15/2006

I need to convert these two textboxes that are in String format into Date
format and I'm not sure how. I tried this and I thought it would work, but
I get the
Conversion from string "TextBox1" to type 'Date' is not valid.
-------------------------

Dim FromDate, ToDate As Date

FromDate = CType("TextBox1", Date)

ToDate = CType("Textbox2", Date)

Thanks and any help is greatly appreciated.
Dec 7 '06 #1
4 13097
GJH
it should be this:
FromDate = CType(TextBox1.Text, Date)

"Phillip Vong" <phillip_vong*at*yahoo*dot*comwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
VS2005 in VB.NET

I have 2 simple textboxes (Textbox1, Textbox2) and they both have dates.

Textbox1=12/31/2006
Textbox2=12/15/2006

I need to convert these two textboxes that are in String format into Date
format and I'm not sure how. I tried this and I thought it would work,
but I get the
Conversion from string "TextBox1" to type 'Date' is not valid.
-------------------------

Dim FromDate, ToDate As Date

FromDate = CType("TextBox1", Date)

ToDate = CType("Textbox2", Date)

Thanks and any help is greatly appreciated.


Dec 7 '06 #2
GJH,

To make it work without ever allowing an exception I do the
following...

Dim tmpDate as DateTime = DateTime.MinValue

If (Not DateTime.TryParse(TextBox1.Text, tmpDate)) Then
' the date is not valid and the tmp value is still MinValue
Else
' the date was parsed and tmpDate has the value
End If

By doing this you can place anything into the TextBox and it will not
cause an exception.

Brennan Stehling
http://brennan.offwhite.net/blog/

GJH wrote:
it should be this:
FromDate = CType(TextBox1.Text, Date)

"Phillip Vong" <phillip_vong*at*yahoo*dot*comwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
VS2005 in VB.NET

I have 2 simple textboxes (Textbox1, Textbox2) and they both have dates.

Textbox1=12/31/2006
Textbox2=12/15/2006

I need to convert these two textboxes that are in String format into Date
format and I'm not sure how. I tried this and I thought it would work,
but I get the
Conversion from string "TextBox1" to type 'Date' is not valid.
-------------------------

Dim FromDate, ToDate As Date

FromDate = CType("TextBox1", Date)

ToDate = CType("Textbox2", Date)

Thanks and any help is greatly appreciated.
Dec 7 '06 #3
OHM
Or use the IsDate(MyDateString) function.

--
OHM
http://TrainingOn.net
"Brennan Stehling" <of******@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
GJH,

To make it work without ever allowing an exception I do the
following...

Dim tmpDate as DateTime = DateTime.MinValue

If (Not DateTime.TryParse(TextBox1.Text, tmpDate)) Then
' the date is not valid and the tmp value is still MinValue
Else
' the date was parsed and tmpDate has the value
End If

By doing this you can place anything into the TextBox and it will not
cause an exception.

Brennan Stehling
http://brennan.offwhite.net/blog/

GJH wrote:
>it should be this:
FromDate = CType(TextBox1.Text, Date)

"Phillip Vong" <phillip_vong*at*yahoo*dot*comwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
VS2005 in VB.NET

I have 2 simple textboxes (Textbox1, Textbox2) and they both have
dates.

Textbox1=12/31/2006
Textbox2=12/15/2006

I need to convert these two textboxes that are in String format into
Date
format and I'm not sure how. I tried this and I thought it would work,
but I get the
Conversion from string "TextBox1" to type 'Date' is not valid.
-------------------------

Dim FromDate, ToDate As Date

FromDate = CType("TextBox1", Date)

ToDate = CType("Textbox2", Date)

Thanks and any help is greatly appreciated.


Dec 7 '06 #4
Thanks everyone!!!

"OHM" <lkjhlkjwrote in message
news:OO**************@TK2MSFTNGP04.phx.gbl...
Or use the IsDate(MyDateString) function.

--
OHM
http://TrainingOn.net
"Brennan Stehling" <of******@gmail.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
>GJH,

To make it work without ever allowing an exception I do the
following...

Dim tmpDate as DateTime = DateTime.MinValue

If (Not DateTime.TryParse(TextBox1.Text, tmpDate)) Then
' the date is not valid and the tmp value is still MinValue
Else
' the date was parsed and tmpDate has the value
End If

By doing this you can place anything into the TextBox and it will not
cause an exception.

Brennan Stehling
http://brennan.offwhite.net/blog/

GJH wrote:
>>it should be this:
FromDate = CType(TextBox1.Text, Date)

"Phillip Vong" <phillip_vong*at*yahoo*dot*comwrote in message
news:Ob**************@TK2MSFTNGP04.phx.gbl...
VS2005 in VB.NET

I have 2 simple textboxes (Textbox1, Textbox2) and they both have
dates.

Textbox1=12/31/2006
Textbox2=12/15/2006

I need to convert these two textboxes that are in String format into
Date
format and I'm not sure how. I tried this and I thought it would
work,
but I get the
Conversion from string "TextBox1" to type 'Date' is not valid.
-------------------------

Dim FromDate, ToDate As Date

FromDate = CType("TextBox1", Date)

ToDate = CType("Textbox2", Date)

Thanks and any help is greatly appreciated.



Dec 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jazper | last post by:
hi can anybody explain that to me: i did the following: - 1. input of char 244 ("ô") into string - 2. convert to getbytes - 3. convert back to string char 244 changed to char 63 ("?")...
1
by: itfgnanvigneshwari | last post by:
hai, as i am new to php field i had a problem in date field. i have table named student with fields fieldname type name varchar...
0
by: Steve | last post by:
Microsoft has introduced a Persian Calendar Class in ASP.net 2.0 http://msdn2.microsoft.com/en-us/library/system.globalization.persiancalendar.aspx I have looked at the methods and the only way...
3
by: Phillip Vong | last post by:
Using VS2005 w/ simple aspx in VB.net I have a simple databound textbox "LastMtgText" in a formview in the Insert template. All I want to do is make the default date of today when someone goes...
1
by: Phillip Vong | last post by:
I have a simple Formview and in the InsertMode I have a calendar and a textbox. All I want is for people to click on a date and the date is populated to the textbox. Here is my simple code and my...
10
by: =?Utf-8?B?TWlrZQ==?= | last post by:
I have a string variable containing a date formatted as YYYYMMDD For example - Dim x as string = "20070314" If I try to perform a type conversion as follows I get an error: Dim y as Date =...
1
by: vadala | last post by:
The requirement is to send start data and end date from java to UI (.net) for a functionality. We are setting the time in java (1.5) before handing it over to WebService (sending to UI ) in...
2
by: Chris H | last post by:
Hi, I'm trying to concatenate a Description (nchar(100)) and Date (datetime) as Description and my initial effort was just "...description+' '+open_date as description..." which throws a date/...
9
by: Apollo1376 | last post by:
Hi, I have a vector<string> Date, which contains all the dates. I will be given a starting date and the ending date. I want to compare the 'staring date' with the dates in the Date vector. I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.