How to convert a string into date

前端 未结 3 830
有刺的猬
有刺的猬 2021-01-25 01:46

I\'m trying to convert a string into date

a = Datumo: 16.09.2012.

d = Mid(a, 9, 2) \' 16 - should be the day
m = Mid(a, 12, 2) \' 09 - month
y = Mid(a, 15, 4)         


        
3条回答
  •  后悔当初
    2021-01-25 02:27

    Thats not a correct use of DateValue, replace

    dt = DateValue(d, m, y) ' Error line 
    dt = DateAdd("d", 1, dt) ' should be 17.09.2012.
    

    with

    dt = DateSerial(y, m, d) 
    dt = DateAdd("d", 1, dt)
    

    or

    dt = 1 + DateAdd("d", 1, dt)
    

提交回复
热议问题