Message Boards Message Boards

0
|
6764 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

[?] Interpret date time string make it fast

Posted 4 years ago

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! :-)

POSTED BY: Daniel Carvalho
4 Replies
Posted 4 years ago

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

POSTED BY: kritesh anand
Posted 4 years ago

How is your answer related to the Wolfram Language?

POSTED BY: Rohit Namjoshi

Thanks!

This is really fast! :-)

POSTED BY: Daniel Carvalho
Posted 4 years ago

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"}}]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract