1
$\begingroup$

I have a list of index symbols and data as follows:

lis={{"^AEX", {{{2015, 1, 2}, {425.89, 428.09, 420.35, 422.28}}, {{2015, 1, 5}, {420.06, 424.58, 410.49, 410.94}}}},
{"^AFLI", {{{2015, 1,2}, {5563.4, 5587.7, 5535., 5586.3}}, {{2015, 1, 5}, {5586.3,5622.1, 5578.9, 5598.3}}}}}

I would like to change the data format to mySQL format "Year", "-", "Month", "-", "Day".

If I use

DateString[lis[[1,2,1,1]], {"Year", "-", "Month", "-", "Day"}]

I get {2015-1-2} for the first entry but I do not know how to change all dates in the whole list.

Does anyone have a hint? Thanks

$\endgroup$
1
  • $\begingroup$ MapAt[DateString[#, {"Year", "-", "Month", "-", "Day"}] &, lis, {All, 2, All, 1}] is one way... $\endgroup$
    – ciao
    Commented Mar 24, 2015 at 21:28

1 Answer 1

2
$\begingroup$

Using your lis...

newlis=MapAt[DateString[#, {"Year", "-", "Month", "-", "Day"}] &, lis, {All, 2, All, 1}]

(*
{{"^AEX", {{"2015-01-02", {425.89, 428.09, 420.35, 422.28}}, 
           {"2015-01-05", {420.06, 424.58, 410.49, 410.94}}}},
 {"^AFLI", {{"2015-01-02", {5563.4, 5587.7, 5535., 5586.3}}, 
            {"2015-01-05", {5586.3, 5622.1, 5578.9, 5598.3}}}}}
*)

If you need date in its own list, brace the map function:

{DateString[#, {"Year", "-", "Month", "-", "Day"}]}

(*
{{"^AEX", {{{"2015-01-02"}, {425.89, 428.09, 420.35, 422.28}}, 
           {{"2015-01-05"}, {420.06, 424.58, 410.49, 410.94}}}},
 {"^AFLI", {{{"2015-01-02"}, {5563.4, 5587.7, 5535., 5586.3}}, 
            {{"2015-01-05"}, {5586.3, 5622.1, 5578.9, 5598.3}}}}}
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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