String manipulation help 
Author Message
 String manipulation help

I'm trying to read in and validate a date field such as 05/06/2000, and I
want to make sure that "/"'s exist in the correct position and check to see
if the year is 2000 and not 00.  Can someone please give me a head start.
Any idea on how to make sure the date is in either an American or European
format?

Thanks,
Rod



Sun, 18 May 2003 03:00:00 GMT  
 String manipulation help
Rod,

I would use the Split function. Check the upper bound of the resulting array
to see if 3 parts were returned. If not, then you can assume that a
different delimiter was used. (Code below is not tested).

Dim DateArray
DateArray = Split(MyDate,"/")
If UBound(DateArray) < 2 Then
  ' The date does not contain / characters
  * Put code here to check for other formats or cause error
Else
  ' The date DOES have / characters. Confirm valid format.
  If DateArray(2) = 0 Then DateArray(2) = 2000
  * Put other validation code here
End If

What do you mean by "European format"? If you mean this:

  US format = mm/dd/yyyy
  European format = dd/mm/yyyyy

...then it will be difficult to check for certain. If you mean this:

  European format = dd-mm-yyyyy

... then modify the above code as follows:

Dim DateArray
DateArray = Split(MyDate,"/")
If UBound(DateArray) < 2 Then
  ' The date does not contain / characters
  ' Check for European format
  DateArray = Split(MyDate,"-")
  If UBound(DateArray) < 2 Then
    ' Date does not contain - charcters either. Error
    * Put error handling code here
  Else
    ' Date is European/military format. Check validity
    If DateArray(2) = 0 Then DateArray(2) = 2000

    * Put other validation code here
  End If

Else
  ' The date DOES have / characters. Confirm valid format.
  If DateArray(2) = 0 Then DateArray(2) = 2000

  * Put other validation code here

End If

I hope this gives you a start.

Charlie


Quote:
> I'm trying to read in and validate a date field such as 05/06/2000, and I
> want to make sure that "/"'s exist in the correct position and check to
see
> if the year is 2000 and not 00.  Can someone please give me a head start.
> Any idea on how to make sure the date is in either an American or European
> format?

> Thanks,
> Rod



Sun, 18 May 2003 03:00:00 GMT  
 String manipulation help
If you're forcing day and month fields to be two digits, you can use mid and
len to verify the string is the correct length and has slashes in the
correct places. If they can be one or two digits, you can use a regular
expression:

  With New RegExp
    .Pattern = "^\d{1,2}\/\d{1,2}\/\d{4}$"
    WScript.Echo .Test("05/06/2000")
    WScript.Echo .Test("5/6/2000")
    WScript.Echo .Test("05/06/00")
  End With

As for making sure about the format, either tell the users the format you
expect, or ask them the format they used.

=-=-=
Steve
-=-=-


Quote:
> I'm trying to read in and validate a date field such as 05/06/2000, and I
> want to make sure that "/"'s exist in the correct position and check to
see
> if the year is 2000 and not 00.  Can someone please give me a head start.
> Any idea on how to make sure the date is in either an American or European
> format?

> Thanks,
> Rod



Sun, 18 May 2003 03:00:00 GMT  
 String manipulation help
Charles & Steve,

Thanks to both of you for your contributions. I am using the mid and len
functions on other date formats, and have actually found another way to
check the dates.  Through COM, I'm able to check the date format on the
database, which is part of what I need, but I'm running into another problem
(maybe somebody can shed some light on the issue.), which is the regional
settings on the server.  I have an events log, which shows the date/time,
LCID, Codepage, session started and user.  The date/time formats seem to
change sporadically, i.e. one day I see 4/11/2000, and on another day I see
11-04-2000.  I see to have exhausted all available resources on regional
settings and how / when they change, but nothing tells me why they change
and how they affect the environment when another logs in.

Thanks,
Rod



Mon, 19 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Beginner String manipulation Help!

2. String manipulation help

3. string manipulation - help!

4. Help for a Newbie: CSV data to be used in string manipulation

5. string manipulation, string routines, etc.

6. Help with String manipulations

7. Please Help, string manipulation

8. GPS NEMA string manipulation with VB5 help

9. GPS NEMA string manipulation with VB5 help

10. Need help with string manipulation...please!

11. Student help - VB4 Proff String Manipulations - urgent

12. Help with VERY simple VB string manipulation

 

 
Powered by phpBB® Forum Software