• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

Converting a string into a date

I connect to an external database that supplies me with a date, but in a string format, like the individual records listed bellow:
"15-Jul-99"
"29-Jul-99"
"05-Aug-1999"
"30-Sep-99"
"22-Oct-99"

I have to take these values and convert them into date variables, so that I can check if the date is earlier than today's date.

Richard
0
Stoke
Asked:
Stoke
1 Solution
 
EDDYKCommented:
DATEfORMAT = CDATE(STR FORMAT)
0
 
StokeAuthor Commented:
That's what I needed.
Thank you
0
 
jimmyoCommented:
Here's another option

Option Explicit

Sub CheckForValidDates()

    Dim strDates() As String, strMsg As String
    Dim i As Integer, intCtr As Integer
    Dim blnValid As Boolean
   
    intCtr = 5
    ReDim strDates(1 To intCtr)
   
    strDates(1) = "15-Jul-99"
    strDates(2) = "29-Jul-99"
    strDates(3) = "05-Aug-1999"
    strDates(4) = "30-Sep-99"
    strDates(5) = "22-Oct-99"
   
    strMsg = "Valid Dates:"
    blnValid = False
   
    For i = 1 To intCtr
        If IsDate(strDates(i)) Then
            strMsg = strMsg & vbCrLf & strDates(i)
            blnValid = True
        End If
    Next i
   
    If blnValid Then
        MsgBox strMsg, vbInformation, "Good Dates"
    End If
       
End Sub
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now