# How to remove hours, minutes, seconds from list

How to remove 0 that represent hours, minutes, and seconds from a date list say a

 a = {{{2007, 1, 3, 0, 0, 0.}, 10.}, {{2007, 1, 4, 0, 0, 0.},20.}, {{2007, 1, 5, 0, 0, 0.}, 30.}}


Result should be:

{{{2007, 1, 3}, 10.}, {{2007, 1, 4},20.}, {{2007, 1, 5}, 30.}}

• One possible solution: b = a /. {x_, y_, z_, i_, j_, k_} -> {x, y, z} though you would need to be careful when you have exactly 6 temporal datum Dec 3, 2014 at 10:30
• {#[[1, 1 ;; 3]], #[[2]]} & /@ a Dec 3, 2014 at 10:59
• This should delete all "0" and "0." elements from your List: b = Delete[a, Position[a, n_ /; Or[n==0,n==0.]]]. Dec 3, 2014 at 11:29

a = {{{2007, 1, 3, 0, 0, 0.}, 10.}, {{2007, 1, 4, 0, 0, 0.},  20.},
{{2007, 1, 5, 0, 0, 0.}, 30.}};

{#[[;; 3]], #2} & @@@ a
(* {{{2007,1,3},10.}, {{2007,1,4},20.}, {{2007,1,5},3 0.}} *)

Cases[a, {x_, y_} :> {x[[;; 3]], y}]


Here is an alternative aiming at maximal robustness: it does only change those entries of the list for which the change makes sense (i.e. the first part looks like a date list). Of course other approaches are much more efficient, so if efficiency is relevant and you know that all entries look the same, this approach is probably not what you want to use...

Replace[a,
{date : {Repeated[_?NumericQ, {6}]}, value_} :> {Take[date, 3],value},
{1}
]


note that by restricting the pattern to exactly 6 repetitions we don't have a problem if there are cases where the date lists have only 1 or 2 elements. By restricting Replace to only work on the 1st level we also don't run into the problem that the list itself could be matched (or any subexpression at a deeper level)...

I find Part the easist way of doing this sort of operation:

a[[All, 1]] = a[[All, 1, 1 ;; 3]];
a

(* {{{2007, 1, 3}, 10.}, {{2007, 1, 4}, 20.}, {{2007, 1, 5}, 30.}} *)