//DATESTR (SDR) // STR = DATESTR(T, N) gives a string column vector of date/time T // in format: // YYYY-MM-DD HH:MM:SS with N (3, 5, or 6) numbers (default = 5) function str = datestr(t, n) if ~exists("n", "local") n = 5; end tlen = size(t, 2); str = ""; select tlen case 1 t = datevec(t); tlen = 6; case 3 case 5 case 6 else error("T must have rows of length 1, 3, 5, or 6.") end t = trimdv(t); if ntlen then t(:,$+1:n) = zeros(size(t,1),n-tlen); end select n case 3 str = msprintf("%4i-%02i-%02i\n", t(:, 1:3)); case 5 str = msprintf("%4i-%02i-%02i %02i:%02i\n", t(:, 1:5)); case 6 str = msprintf("%4i-%02i-%02i %02i:%02i:%02i\n", t(:, 1:6)); else error("n must be 3, 5, or 6.") end endfunction