# Convert an imported date from excel into a format that mathematica can recognize [closed]

ToString[dates1[[1]]] yields the following:

"DateObject[{2006, 10, 5, 0, 0, 0.}, Instant, Gregorian, -5.]"

I would like to convert the the imported list dates1 to:

"DateObject[{2006, 10, 5}, Day, Gregorian, -5.]"

Ultimately my goal is to extract specific dates using Position[] so I can identify ranges of dates within the data.

## closed as off-topic by Sektor, Alexey Popkov, LCarvalho, Edmund, gwrDec 27 '17 at 15:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sektor, Alexey Popkov, LCarvalho, Edmund, gwr
If this question can be reworded to fit the rules in the help center, please edit the question.

• No need to convert anything: Position[dates1, DateObject[{your, date, here, ___}, ___]] should be all you need. – b3m2a1 Dec 21 '17 at 15:41
• Thank you very much. This was the trick I needed. – Jeremiah Stafford Dec 21 '17 at 17:59
• @JeremiahStafford how could that be the case if you say you have strings there: "..."? – Kuba Dec 22 '17 at 8:09

Try this:

obj = Characters[
"DateObject[{2006, 10, 5, 0, 0, 0.}, Instant, Gregorian, -5.]"];


then

StringInsert[
StringJoin[Drop[Characters[obj], {26, 45}]], "}, Day,", {25}]

(*  "DateObject[{2006, 10, 5,}, Day, Gregorian, -5.]"  *)


Have fun!

• Thank you for your response. I'll dig into this a bit, the first solution solved my issue. Appreciate your response. – Jeremiah Stafford Dec 21 '17 at 18:00

As b3m2a1 notes in comments, you can extract positions of specific dates using usual patterns, no need to convert date objects to strings:

Position[dates1, DateObject[{your, date, here, ___}, ___]]