1
$\begingroup$

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.

$\endgroup$

closed as off-topic by Sektor, Alexey Popkov, LCarvalho, Edmund, gwr Dec 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.

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

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!

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

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, ___}, ___]]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.