i want to shift this timetable for 1 day it means i want this, start from 03-jan-2018 regardless of hours

 채택된 답변

dpb
dpb 2018년 10월 25일

0 개 추천

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

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 2018년 10월 31일
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...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

jonas
jonas 2018년 10월 25일
편집: jonas 2018년 10월 25일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

질문:

2018년 10월 25일

댓글:

dpb
2018년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by