shifting time in timetable

15 views (last 30 days)
pooria mazaheri
pooria mazaheri on 25 Oct 2018
Commented: dpb on 31 Oct 2018
i want to shift this timetable for 1 day it means i want this, start from 03-jan-2018 regardless of hours

Accepted Answer

dpb
dpb on 25 Oct 2018
Not sure what the "want" really means--the present time just a day later for each observation or what, precisely?
On the presumption that's the correct guess, then
TT.Time=TT.Time+1;
  2 Comments
Peter Perkins
Peter Perkins on 31 Oct 2018
This works, but for two reasons I would recommend adding caldays(1) rather than just 1.
1) For backwards compatibility reasons, 1 is interpreted as a datenum, i.e. days(1). But that's perhaps not obvious to someone reading the code at some later time.
2) Getting in the habit of using caldays for calendar arithmetic is a good idea, because someday, you're going to be working with zoned datetimes, and adding a day to a Sat that happens to be the day before a DST shift. days(1) means "exactly 24 hours", which probably isn't what you'd want, while caldays(1) means "one calendar day", which probably is.
>> dt = datetime(2018,11,3,14,0,0,'TimeZone','America/New_York')
dt =
datetime
03-Nov-2018 14:00:00
>> dt + days(1)
ans =
datetime
04-Nov-2018 13:00:00
>> dt + caldays(1)
ans =
datetime
04-Nov-2018 14:00:00
days is mostly intended as a shorthand for "24 hours" when you are working with "exact times" and durations.
dpb
dpb on 31 Oct 2018
Good points, Peter.
I didn't have a klew as to what the OP was asking so was hoping for a response as to what the desire really was so I just took the shortcut to try to begin the conversation. Hadn't realized OP even came back until saw your comment just now...

Sign in to comment.

More Answers (1)

jonas
jonas on 25 Oct 2018
Edited: jonas on 25 Oct 2018
Simply shifting the time without affecting the data
TT.Time = dateshift(TT.Time,'start','day')
Changing the format (hiding the time of day)
TT.Time.Format = 'dd-MMM-yyyy'
Calculating a daily average
TT2 = retime(TT,'daily','mean')
These are the answers to three possible interpretations of your question. Perhaps you could describe your problem a bit better next time.

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!