[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

convert string to date in vb6

Posted on 2004-10-05
3
Medium Priority
?
1,514 Views
Last Modified: 2008-02-01
in vb6 I have a string 11012004 that I want to convert to be read as a date. I tried to use the cdate but got type mismatch errors. Anyone know how this could be done?
Thanks
0
Comment
Question by:cdb424ttm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Expert Comment

by:JR2003
ID: 12225944
Private Sub Command1_Click()
    Dim sDate As String
    Dim dDate As Date
    sDate = "11012004"
    dDate = CDate(Right$(sDate, 4) & "-" & Mid$(sDate, 3, 2) & "-" & Left$(sDate, 2))
    MsgBox dDate
End Sub
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12225965
as long as the string is of the same length:

Dim sDate As String
Dim TheDate As Date

sDate = "11012004"
sDate = Format(sDate, "@@/@@/@@@@")

If IsDate(sDate) Then
    TheDate = CDate(sDate)
End If

Debug.Print Format(TheDate, "mmm dd, yyyy")
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 12227493
You can also use DateSerial:

Private Sub Command1_Click()
Dim dtmDate As Date
Dim strDate As String

    strDate = "11012004"
   
    dtmDate = DateSerial(Mid$(strDate, 5, 4), Mid$(strDate, 1, 2), Mid$(strDate, 3, 2))
    MsgBox dtmDate
End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question