Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.4K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Import string dates using US date format?

Posted 6 years ago
POSTED BY: Andrew Burnett
4 Replies
Posted 6 years ago

That's great. Thank you very much.

POSTED BY: Andrew Burnett
Posted 6 years ago
POSTED BY: Rohit Namjoshi
Posted 6 years ago

Hi Rohit, Thanks for your answer. Unfortunately, I can't get it to work, and I am obviously doing something dumb. Just to be clear, I am importing a csv log file that contains dates in the format 06/11/2019 10:55:44 AM. I want to convert them to DateObjects. The conversion does work, but it complains that it is ambiguous. Adding the format list, as you suggested, produces a "cannot be interpreted as a date." message

Here is the code snippet - can you see what I am doing wrong?

ecicc = Import["/Users/andy/Downloads/participants_497478659.csv"]; In[65]:= ecicc[[2, 3]] Out[65]= "06/11/2019 10:55:44 AM" ecicc[[2 ;; All, 3]] = DateObject[{#, {"Month", "/", "Day", "/", "Year", "hour", ":", "Minute", ":", "Seconds"}}] & /@ ecicc[[2 ;; All, 3]]; ecicc[[2 ;; All, 4]] = DateObject[{#, {"Month", "/", "Day", "/", "Year", "hour", ":", "Minute", ":", "Seconds"}}] & /@ ecicc[[2 ;; All, 4]]; DateObject::str: String 06/11/2019 10:58:51 AM cannot be interpreted as a date. General::stop: Further output of DateObject::str will be suppressed during this calculation. DateObject::str: String 06/11/2019 12:54:08 PM cannot be interpreted as a date. General::stop: Further output of DateObject::str will be suppressed during this calculation.

POSTED BY: Andrew Burnett
Posted 6 years ago

Hi Andrew,

To parse a date string in M/D/Y format:

d = DateObject[{"6/10/2019", {"Month", "/", "Day", "/", "Year"}}]
DateString[d, "ISODateTime"]
(* 2019-06-10T00:00:00 *)
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