# Setting up time and date

1 view (last 30 days)
Maaz Madha on 20 Jan 2021
Commented: Cris LaPierre on 20 Jan 2021
Hi
I'm trying to set up a date and time where it reads from 1:00 today(as in today the time function not today today) till 00:30 tomorrow in consecutives of 30 minutes(half an hour).
%%To determine low load hours and high load hours for valley filling%%
clc
clear
% t1.Format=('today,1:00')
% t2.Format=('tomorrow,00:30')
datetime.InputFormat('default','yyyy-MM-dd hh:mm:ss') %idk how to do this sorry
t1 = datetime('today,1:00:00');
t2 = datetime('tomorrow,00:30:00');
% t1 = datetime(2020,1,1,1,0,0);
% t2 = datetime(2020,1,2,00,30,0);
%t=t1.Format:hours(0.5):t2.Format;
datetime1=datenum(t);%convert it into strings
ts=datetime1*24*60*60;
ts1=zeros(48,1);%preallocation k1=zeros(48,1);
ts2=zeros(48,1);
figure(1)
% figure(1)
% a=plot(k,load)%%plotting power with regards to k
delta_y=diff(load);%finding difference between one point from another
delta_x=diff(ts);%difference k
delta_x=delta_x';
slope=delta_y/delta_x;
slope=slope(:,1); %find the gradient of the demand to see where load is
%increasing or decreasing
for k=1:length(slope)
if sign(slope(k))==-1 %%when load is decreasing
d(k)=(slope(k));
if d(k)~=0%removing all the zeros
ts1(k)=(k);%gets the indices
end
e(k)=(slope(k));
if e(k)~=0%removing all the zeros
ts2(k)=k;%gets the indices for when load is increasing
end
end
end
ts1=nonzeros(ts1');%time instants
ts2=nonzeros(ts2')
I want to be able to convert the date and time(today and tomorrow with the fixed times) into seconds so it can plot the graph but also be updated everyday so the values stay relevant.

Cris LaPierre on 20 Jan 2021
Edited: Cris LaPierre on 20 Jan 2021
Not sure I fully understand, but try this for setting up you time vector.
tVec = today('datetime')+hours(13:.5:24.5)'
tVec = 24×1 datetime array
20-Jan-2021 13:00:00 20-Jan-2021 13:30:00 20-Jan-2021 14:00:00 20-Jan-2021 14:30:00 20-Jan-2021 15:00:00 20-Jan-2021 15:30:00 20-Jan-2021 16:00:00 20-Jan-2021 16:30:00 20-Jan-2021 17:00:00 20-Jan-2021 17:30:00 20-Jan-2021 18:00:00 20-Jan-2021 18:30:00 20-Jan-2021 19:00:00 20-Jan-2021 19:30:00 20-Jan-2021 20:00:00 20-Jan-2021 20:30:00 20-Jan-2021 21:00:00 20-Jan-2021 21:30:00 20-Jan-2021 22:00:00 20-Jan-2021 22:30:00 20-Jan-2021 23:00:00 20-Jan-2021 23:30:00 21-Jan-2021 00:00:00 21-Jan-2021 00:30:00
##### 2 CommentsShowHide 1 older comment
Cris LaPierre on 20 Jan 2021
Either works. When in doubt, you can aloways consult the documentation.