'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 1:[1]
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)
Solution 2:[2]
In VB6 I've always found that the easiest way to deal with time/date values is to cast them as a Double (simply declare a variable as type Double, then assign the value from whatever source). Then, simply deal with either the integer part (days) or the fractional part (fractional days). For example, seconds are just TimeStamp/86400.0, etc. When a variable is declared as Date, it's actually stored as a Double, so I just use that as my basic TimeStamp type. VB is pretty good about re-formatting into a time/date string when printing, and it makes time-based calculations really straight-forward.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alex K. |
Solution 2 | Mark Moulding |