Have a look at time series similarity functions, such as dynamic time warping.
They can be used with e.g. DBSCAN but NOT with k-means (you cannot compute a reasonable "mean" for these distances; k-means is really designed for squared Euclidean distances).