I just have myvar="gi_db_comuni-2026-07-10-b893f.zip"
how to get date?
note:
before and after the date are lenght variable
Printable View
I just have myvar="gi_db_comuni-2026-07-10-b893f.zip"
how to get date?
note:
before and after the date are lenght variable
Code:Sub main()
Dim myvar As String
Dim t() As String
Dim regex As RegExp
Dim mc As MatchCollection
Dim m As Match
Dim mydate As Date
'First way
myvar = "gi_db_comuni-2026-07-10-b893f.zip"
t = Split(myvar, "-")
mydate = DateSerial(CInt(t(1)), CInt(t(2)), CInt(t(3)))
Debug.Print mydate
'Second way - needs reference to VBScript Regular Expressions
Set regex = New RegExp
regex.Pattern = "\.*?-(\d{4}-\d{2}-\d{2})\.*"
regex.IgnoreCase = True
regex.Global = True
Set mc = regex.Execute(myvar)
If mc.Count = 1 Then
Set m = mc.Item(0)
t = Split(m.SubMatches(0), "-")
mydate = DateSerial(CInt(t(0)), CInt(t(1)), CInt(t(2)))
End If
End Sub