Skip to content
Advertisement

How can I parse just a section of big log based on datetime in python

I wanted to parse just a section of any given log. I just need to start from start_time of my log and end at end_time of my code. The datetime format is “[2021-09-14 21:56:01.768]” So basically suppose I needed to start from “[2021-09-14 21:56:01.768]” part of log and end at “[2021-09-14 21:58:56.608]” and need to parse content between these two, parsing the content I have already written, but not understanding how to take this time section from code.

Sample log:

JavaScript

Advertisement

Answer

This method below takes the start and end date along with the string logs and returns the logs in between two dates.

JavaScript

It will print out:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement