Forum Discussion
kregggower
Jan 17, 2023Copper Contributor
date convertion (s)
need help converting a date formatted 20230117093739 YYYYMMDDHHMMSS to 01/17/2023 (in one cell) 9:37:39 AM (in the next cell). i normally use this mid string Date: Mid([INB_DATE_TIME],5,2) & "/" & ...
arnel_gp
Jan 18, 2023Iron Contributor
you can also create a custom function and call it from your query:
Public Function fnToDateTime(ByVal var As Variant, ByVal whichPart As String) As Variant
' arnelgp
'
' Note:
'
' whichPart can be "D" (for date) or "T" for time
'
Static pvar As Variant
Static retDate As Date, retTime As Date
Dim d As String, t As String
If IsNull(var) Then
Exit Function
End If
If var <> pvar Then
d = Left$(var, 8)
t = Mid$(var, 9)
retDate = DateSerial(Left$(d, 4), Mid$(d, 5, 2), Right$(d, 2))
retTime = #12:00:00 AM#
If Len(t) <> 0 Then
retTime = CDate(Left$(t, 2) & ":" & Mid$(t, 3, 2) & ":" & Right$(t, 2))
End If
pvar = var
End If
Select Case whichPart
Case "D"
fnToDateTime = retDate
Case "T"
fnToDateTime = retTime
End Select
End Function
on your Query:
select [strDateField], fnToDateTime([strDateField], "D") As Dte, fnToDateTime([strDateField], "T") As Tim
from yourTable;
kregggower
Jan 18, 2023Copper Contributor
arnel_gp,
Thank you for you reply. but i've just starting to look into VB language and it may as well be Hieroglyphics. it is over my head (for now). but thank you very much for your input.
Thank you for you reply. but i've just starting to look into VB language and it may as well be Hieroglyphics. it is over my head (for now). but thank you very much for your input.