I am using the datefinder module in python and I need to extract the DateTime from a string but I am getting multiple dates from the string that contains only one date and time.
Code:
import datefinder
def date_using_datefinder(date_string):
matches = datefinder.find_dates(date_string)
for match in matches:
print(match)
Input:
test3='''
[26/08/2018 06:58:29.126900]
[26/03/2004 06:58:29.126985][SDAP_CODEC][JET_AT_JUMP][43][HTXXHTXX] DUST_RPOP:QFI:9
[02/06/2003 06:58:29.254621][SDAP_CODEC][JET_AT_JUMP][43][HTXXHTXX] DUST_RPOP:QFI:9
[20/05/2022 06:58:29.124898][SDAP_CODEC][JET_AT_JUMP][43][HTXX] DUST_RPOP:QFI:9
[26/08/2020 06:58:29.136579][ALST][stx][29][ggg] JET_AT_JUMP:TRUX_MSGD_HTXX:13265261686865256:QWERT_DUMPING_TDD:45:DUST_RPOP_CVX:32:AXTP_DI:65576
'''
Output:
2018-08-26 06:58:29.126900
2004-03-26 06:58:29.126985
2003-02-06 06:58:29.254621
2022-05-20 06:58:29.124898
2020-08-26 06:58:29.136579
2045-08-02 00:00:00
2032-08-02 00:00:00
why these last two dates are appearing which is I guess nowhere in the string.
PS: I tried DateUtil Module also but it's showing ParseError.
just for reference, the code is:
from datetime import datetime
from dateutil import tz
import dateutil.parser as dparser
import warnings
warnings.filterwarnings('ignore')
def date_Using_UtilModule(date_string):
res = dparser.parse(date_string, fuzzy = True)
return res
res = date_Using_UtilModule("[26/08/2020 06:58:29.136579][ALST][stx][29][ggg] JET_AT_JUMP:TRUX_MSGD_HTXX:13265261686865256:QWERT_DUMPING_TDD:45:DUST_RPOP_CVX:32:AXTP_DI:65576")
print(res)
output:
ParserError: Unknown string format: [26/08/2020 06:58:29.136579][ALST][stx][29][ggg] JET_AT_JUMP:TRUX_MSGD_HTXX:13265261686865256:QWERT_DUMPING_TDD:45:DUST_RPOP_CVX:32:AXTP_DI:65576
Note: using regex will not work in my case because my log lines can have random patterns and also any DateTime format, or I can say not want to use regex.