Search code examples
vb6

How to remove time from date time in VB6


i am currently working with VB6, and i have this value of date that is like this:

2022-02-26T12:06:10+02:00

I followed this url too VB6: How to remove the Time part from Date type

but doesnt work especially the last one still shows the date as

2022-02-26T12:06:10+02:00

This is my code

Dim tdate As String

    tdate = format$("2022-02-26T12:06:10+02:00" , "m/d/yyyy")

and the output is still 2022-02-26T12:06:10+02:00


Solution

  • Your input is a string in ISO8601 format. As its a string in a fixed format the easiest way is to just chop off the first 10 characters.

    isoDateTimeString = "2022-02-26T12:06:10+02:00"
    

    To get the date part as another string:

    Dim dateAsString As String
    dateAsString = Left$(isoDateTimeString, 10)
    '// for 2022-02-26
    

    Or to get it as a Date type:

    Dim dateAsDateType As Date
    dateAsDateType = CDate(Left$(isoDateTimeString, 10))
    '// for 26/02/2022 (or whatever your locale format is)