473,325 Members | 2,442 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,325 software developers and data experts.

Testing fro valid dates

Hi,
is there an easy way in vb to test a string for a valid date (to pass to
a db) like YYYYMMDD or YYYY-MM-DD ?

Thanks
Alex

Nov 20 '05 #1
5 998
* alex <ai******@hotmail.com> scripsit:
is there an easy way in vb to test a string for a valid date (to pass
to a db) like YYYYMMDD or YYYY-MM-DD ?


Maybe with 'DateTime.ParseExact'. In Whidbey, there will be appropriate
'TryParse*' methods even for 'DateTime'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Hi Alex,

You can convert the string to a date and test it with isdate. But do it
inside a try catch block or it will fail:
Dim st2 As String

st2 = "14/35/03"

Try

If IsDate(CDate(st2)) Then

MessageBox.Show(st2)

End If

Catch

MessageBox.Show("not a valid date")

End Try

HTH,

Bernie Yaeger

"alex" <ai******@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Hi,
is there an easy way in vb to test a string for a valid date (to pass to
a db) like YYYYMMDD or YYYY-MM-DD ?

Thanks
Alex

Nov 20 '05 #3
in addition
as far as i know you don't even have to convert it for that
isdate("1/12/03") will work 2

eric

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Hi Alex,

You can convert the string to a date and test it with isdate. But do it
inside a try catch block or it will fail:
Dim st2 As String

st2 = "14/35/03"

Try

If IsDate(CDate(st2)) Then

MessageBox.Show(st2)

End If

Catch

MessageBox.Show("not a valid date")

End Try

HTH,

Bernie Yaeger

"alex" <ai******@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Hi,
is there an easy way in vb to test a string for a valid date (to pass to
a db) like YYYYMMDD or YYYY-MM-DD ?

Thanks
Alex


Nov 20 '05 #4
Hi Eric,

My system threw an error if isdate() had a 'non-date' argument.

Bernie

"EricJ" <ericRéMo**@ThiSomnipack.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
in addition
as far as i know you don't even have to convert it for that
isdate("1/12/03") will work 2

eric

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Hi Alex,

You can convert the string to a date and test it with isdate. But do it
inside a try catch block or it will fail:
Dim st2 As String

st2 = "14/35/03"

Try

If IsDate(CDate(st2)) Then

MessageBox.Show(st2)

End If

Catch

MessageBox.Show("not a valid date")

End Try

HTH,

Bernie Yaeger

"alex" <ai******@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Hi,
is there an easy way in vb to test a string for a valid date (to pass to a db) like YYYYMMDD or YYYY-MM-DD ?

Thanks
Alex



Nov 20 '05 #5
strange you'll have to work around that then
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
Hi Eric,

My system threw an error if isdate() had a 'non-date' argument.

Bernie

"EricJ" <ericRéMo**@ThiSomnipack.be> wrote in message
news:3f**********************@reader0.news.skynet. be...
in addition
as far as i know you don't even have to convert it for that
isdate("1/12/03") will work 2

eric

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
Hi Alex,

You can convert the string to a date and test it with isdate. But do it inside a try catch block or it will fail:
Dim st2 As String

st2 = "14/35/03"

Try

If IsDate(CDate(st2)) Then

MessageBox.Show(st2)

End If

Catch

MessageBox.Show("not a valid date")

End Try

HTH,

Bernie Yaeger

"alex" <ai******@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
> Hi,
> is there an easy way in vb to test a string for a valid date (to
pass
to > a db) like YYYYMMDD or YYYY-MM-DD ?
>
> Thanks
> Alex
>



Nov 20 '05 #6

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

Similar topics

2
by: Konstantin Zakharenko | last post by:
Hello, Our QA team have running a lot of test scripts (for automated regression testing), they run them on the different databases (Oracle/MS SQL). Several of those tests are dependent on the...
0
by: Jonathan Allen | last post by:
We have found that our method of testing does not match traditional text-book methodologies. I decided to write a short white paper on it so that I could get your opinions. Does anyone else use...
5
by: Cogito | last post by:
In a form I have two text fields. In one of them the user enters a decimal number and in the other a hexadecimal number. What code can be used to validate that the entered text is numeric and to...
6
by: Rookie Card | last post by:
I know this is a very common issue but cannot find a thread that resolves the issue. I need to re-format my dates to "MMM d, yyyy". The problem I have is I have an MSSQL database that allows...
28
by: romy | last post by:
What's the easiest way to verify the user had entered a valid date ?
3
by: Water Cooler v2 | last post by:
Here's my understanding as of now. If I were writing a function bool IsValidContact(Offerer objOfferer, Accepter objAccepter, TermsAndConditions objTermsAndConditions); Before writing the...
17
by: Christoph Schneegans | last post by:
Hi! I would like to announce XHTML Proxy, a service that allows more accurate testing of XHTML documents. <http://hixie.ch/advocacy/xhtml> states that "Sending XHTML as text/html Considered...
17
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
16
by: Mike P | last post by:
How would I write some Javascript to test whether a date is in the past or not? I need to only accept either the current date or future dates. *** Sent via Developersdex...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.