[?] Interpret date time string make it fast

Hello,

In a log data from a basic text file I have this date-time format:

"[06/Jun/2018:13:35:32]"

I did a function to convert it to Wolfram Language date object, cleaning up the “[”, “]” and a central “:”

fixDateString[val_String] := 
 Interpreter["DateTime"][
  StringReplacePart[StringReplace[val, {"[" -> "", "]" -> ""}], 
   " ", {12, 12}]]

fixDateString["[01/Jun/2018:02:05:42]"]

DateObject[{2018, 6, 1, 2, 5, 42}, "Instant", "Gregorian", -3.]

Surprisingly it is a very slow operation!!!

Any suggestion about how to make it faster is appreciated! I am using Parallelize to use my CPUs available.

Thanks! :slight_smile:

Hi Daniel,

Interpreter connects to Wolfram servers which is why it is slow. Try this instead.

DateObject@DateString[
  {StringTake["[01/Jun/2018:02:05:42]", {2, -2}], 
   {"Day", "/", "Month", "/", "Year", ":", "Hour", ":", "Minute", ":", "Second"}}]

Thanks!

This is really fast! :slight_smile:

You can create a date with new Date(). There are four possible ways to use new Date():

With a date-string
With date arguments
With a timestamp
With no arguments

To get to know more then you can get to enroll for data analytics online courses

How is your answer related to the Wolfram Language?