Home > bml > utils > bml_date2sec.m

bml_date2sec

PURPOSE ^

BML_DATE2SEC transforms a cell-array of date strings to seconds from

SYNOPSIS ^

function sec=bml_date2sec(date,t0)

DESCRIPTION ^

 BML_DATE2SEC transforms a cell-array of date strings to seconds from
 midnight

 date - {N,1} cell array with dates in the format '25-Jul-2017 12:14:25'
 t0 - string representing reference time of day. Defalts to '00:00:00'

 returns a [N,1] array of doubles with the number of seconds since
 midnight

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function sec=bml_date2sec(date,t0)
0002 
0003 % BML_DATE2SEC transforms a cell-array of date strings to seconds from
0004 % midnight
0005 %
0006 % date - {N,1} cell array with dates in the format '25-Jul-2017 12:14:25'
0007 % t0 - string representing reference time of day. Defalts to '00:00:00'
0008 %
0009 % returns a [N,1] array of doubles with the number of seconds since
0010 % midnight
0011 
0012 if ~exist('t0','var')
0013   t0 = '00:00:00';
0014 end
0015 
0016 if ~iscell(date)
0017   date = {date}; 
0018 end
0019 
0020 t0 = datenum(t0);
0021 sec = zeros(numel(date),1);
0022 for i=1:numel(date)
0023   if length(date{i})>=20
0024     sec(i)=datenum(date{i}(13:20));
0025   else
0026     sec(i)=nan;
0027   end
0028 end
0029 
0030 sec=(sec-datenum(t0))*24*60*60;

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005