# Import string dates using US date format?

**URL:** <https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297>\
**Category:** Questions\
**Tags:** data-science, curated-data, import-and-export\
**Created:** [June 30, 2019, 6:35pm UTC](https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297 "2019-06-30T18:35:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyburnett](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@andyburnett](https://community.wolfram.com/u/andyburnett)\
**Post date:** [June 30, 2019, 6:35pm UTC](https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297/1 "2019-06-30T18:35:09Z")

</div>

I have imported a log file that contains dates in (M/D/Y) format. Because the dates are in June,

```
DateObject[#]&

```

Reports that the date string is ambiguous. How might I tell the Notebook - not the whole mathematica system - the date format of the file?

I tried

```
DateObject[#, DateFormat -> {"Month", "/", "Day", "/", "Year"}] & 

```

But it didn’t have any effect on the warming messages.

Thanks  
Andy

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [June 30, 2019, 8:59pm UTC](https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297/2 "2019-06-30T20:59:06Z")

</div>

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 *)

```

---

<div class="post-metadata">

**Author:** ![andyburnett](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@andyburnett](https://community.wolfram.com/u/andyburnett)\
**Post date:** [July 1, 2019, 3:00pm UTC](https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297/3 "2019-07-01T15:00:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [July 1, 2019, 7:36pm UTC](https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297/4 "2019-07-01T19:36:35Z")

</div>

Andrew,

The pattern has to match exactly

```
d = DateObject[{"06/11/2019 10:55:44 AM", {"Month", "/", "Day", "/", 
    "Year", " ", "Hour12", ":", "Minute", ":", "Second", " ", "AMPM"}}];
DateString[d, "ISODateTime"]
(* 2019-06-11T10:55:44 *)

```

Change AM to PM

```
d = DateObject[{"06/11/2019 10:55:44 PM", {"Month", "/", "Day", "/", 
    "Year", " ", "Hour12", ":", "Minute", ":", "Second", " ", 
    "AMPM"}}];
DateString[d, "ISODateTime"]
(* 2019-06-11T22:55:44 *)

```

---

<div class="post-metadata">

**Author:** ![andyburnett](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@andyburnett](https://community.wolfram.com/u/andyburnett)\
**Post date:** [July 1, 2019, 9:15pm UTC](https://community.wolfram.com/t/import-string-dates-using-us-date-format/14297/5 "2019-07-01T21:15:00Z")

</div>

That’s great. Thank you very much.
