using datetime() in retrieving data
2 views (last 30 days)
Assuming I am using datetime() to refer to the date and time that some data has accured in.
I am using 'date' in further comparison to retrive some data, now is there any syntax I may use in this that would allow me for example to retrive the data happened in a certain day for all the years, (ex: the data happened in 1st october from all the years we have) or for a certain hour from all days in months in years?
Siddharth Bhutiya on 30 Sep 2021
Once you have created a datetime array, you could use functions like month, day, year, etc to get the corresponding field values from the datetime. Then as KSSV suggested above, you could use those to index and filter your datetimes.
4×1 datetime array
>> d(month(d) == 10 & day(d) == 1) % Get 1st October for all years
2×1 datetime array
If you want to filter your datetimes for values between two points in time then you could also use something like isbetween: https://www.mathworks.com/help/matlab/ref/datetime.isbetween.html
More Answers (1)
KSSV on 30 Sep 2021
Read about datevec. This will split your date into year, month, day, hour, minute and secobd. From here you can use logial indexing and get the indices.
idx = month == 10 & day == 1 ;