TransWikia.com

How to merge two lists of strings (date and time) and treat them as DateObject

Mathematica Asked by Vocis on May 21, 2021

I would like to merge two lists of strings (date and time) from my csv and then treat it as a DateObject:

time = Import[
    "C:UsersData Chanel.csv",
    "Table",
    "FieldSeparators" -> ";",
    NumberPoint -> ","][[3, 3 ;;]];
    date = Import[
         "C:UsersData Chanel.csv",
         "Table",
         "FieldSeparators" -> ";",
         NumberPoint -> ","
    ][[2, 3 ;;]];


combFunc =  Function[{date, time}, StringJoin[ToString /@ {date, time}], Listable][date, time]

And the result is: enter image description here

timeData = DateObject[combFunc, {"Day", ". ", "MonthName", ". ", "Year", " ", "Hour", ":","Minute", ":", "Second"}]

which changes year and time in first step as it can be seen in the picture

and DateObject doesn’t work even when I apply it only on time or only on date or their combination.

Do you have any idea how to fix it?
Thank you for your advices!
Here is the link for the csv:

https://gofile.io/d/I6scno

2 Answers

Assume you imported the data in time and date. Then we need to assemble these two in a form that suits the DateObject:

dat= MapThread[(#1 <> " " <> #2) &, {time, date}];

Then we map DateObject with the necessary options onto every element of the list dat:

dates = DateObject[{#, {"Hour", "Minute", "Second" , "Day", 
      "MonthName", "YearShort"}} ] & /@ dat

dates is a list of DateObject;

date[[1;;2]]

Correct answer by Daniel Huber on May 21, 2021

imported = Import["Data Chanel 1.csv", "Table", "FieldSeparators" -> ";"];

dates = DateObject[#2 ~~ " " ~~ #3]& @@@ Transpose@ imported[[All, 2 ;;]]

enter image description here

Answered by MarcoB on May 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP