A better CDate for VB6

后端 未结 8 724
悲哀的现实
悲哀的现实 2020-12-21 05:43

We have a a VB6 app (in a COM component) which uses CDate() to take a string and cast it to a Date, for storing in a database.

Depending on if we want the applicatio

8条回答
  •  悲&欢浪女
    2020-12-21 06:27

    I don't know of an easy solution. You could Split the input string into sub-strings by the delimiter, and then use DateSerial to recombine the year, month and hour numbers into a native VB6 Date variable. Something like this below. If you need to support a lot of locales, this could get complicated (see Bob's answer). Mind you, so would using DateTime.ParseExact.

    sInput = "1/3/71"
    Dim splt() As String
    splt = Split(sInput, "/")
    dte = DateSerial(splt(2) + 1900, splt(1), splt(0))  ' dd/mm/yy'
    

提交回复
热议问题