none
Spliting Date/Time string RRS feed

  • Question

  • Hi,

    I have an Outlook.AppointmentItem property string which is a concatenation of dd/mm/yyyy and HH:MM:

    .Start = Nz(Me.eventstart, "") & " " & Nz(Me.time, "")
    

    e.g "28/08/2011 18:45"
    How do I split and extract from it two substrings, one of date and one of the time ?

    THNX ALOT

    Saturday, August 27, 2011 8:16 AM

Answers

  •  Dim starting As String, splitted As Variant, length As Integer
     Dim theDate As String, theTime As String
     starting = "28/08/2011 18:45"
     splitted = Split(starting, " ")
     length = UBound(splitted)
     If length < 1 Then
      ' date or time is missing
     Else
      theDate = splitted(0)
      theTime = splitted(1)
     End If
    

    you can simply use a variant variable for an array, to get your string splitted and then verify the content, but what do you want to do, if date or time is missing?

     


    please, mark this as answer if it is THE answer
    ----------------
    Diego Cattaruzza
    Microsoft MVP - Visual Basic: Development
    blog: http://community.visual-basic.it/Diego
    web site: http://www.visual-basic.it
    • Marked as answer by Roey Peretz Saturday, August 27, 2011 11:47 AM
    Saturday, August 27, 2011 9:43 AM

All replies

  •  Dim starting As String, splitted As Variant, length As Integer
     Dim theDate As String, theTime As String
     starting = "28/08/2011 18:45"
     splitted = Split(starting, " ")
     length = UBound(splitted)
     If length < 1 Then
      ' date or time is missing
     Else
      theDate = splitted(0)
      theTime = splitted(1)
     End If
    

    you can simply use a variant variable for an array, to get your string splitted and then verify the content, but what do you want to do, if date or time is missing?

     


    please, mark this as answer if it is THE answer
    ----------------
    Diego Cattaruzza
    Microsoft MVP - Visual Basic: Development
    blog: http://community.visual-basic.it/Diego
    web site: http://www.visual-basic.it
    • Marked as answer by Roey Peretz Saturday, August 27, 2011 11:47 AM
    Saturday, August 27, 2011 9:43 AM
  • you can simply use a variant variable for an array, to get your string splitted and then verify the content, but what do you want to do, if date or time is missing?

    It is only part of retrieving and formatting fields from an appointment item.
    I will force Date, Time and Subject upon creating an appointment.

    Grazie !

    Saturday, August 27, 2011 11:47 AM
  • One way -

    Sub test()
    Dim s As String
    Dim dt As Date
    Dim sDate As String, sTime As String
        s = "28/08/2011 18:45"
    
       dt = CDate(s)
        sDate = Format(dt, "dd/mm/yyyy")
       sTime = Format(dt, "hh:nn")
        MsgBox sDate & vbCr & sTime
    
    End Sub

    Peter Thornton

    Monday, August 29, 2011 9:41 PM
    Moderator