4 Day temperature comparison, including current day

2 ビュー (過去 30 日間)
Mark Clark
Mark Clark 2019 年 2 月 5 日
編集済み: Yair Altman 2019 年 2 月 6 日
How can I include the current day in the 3 day temperature comparison.
[datetime('today')-days(0),datetime('today')], gives an error
  6 件のコメント
Mark Clark
Mark Clark 2019 年 2 月 5 日
'DateRange' value must have an end date and time later than the start date and time.
Error message when I use [datetime('today')-days(0),datetime('today')]
Guillaume
Guillaume 2019 年 2 月 5 日
Is that the full text of the error message. Usually it also states which line(s) is responsible for the error. This is essential information we need, particularly since I cannot see anywhere in your code where you use [datetime('today')-days(0),datetime('today')].
On the other hand the error message is clear. The two dates you pass must be different, with the second one later than the first. Of course, subtracting 0 days from a date doesn't change that data, so [datetime('today')-days(0),datetime('today')] is twice the same date.
It's unclear what you expected to do with that.

サインインしてコメントする。

採用された回答

Omer Yasin Birey
Omer Yasin Birey 2019 年 2 月 5 日
編集済み: Omer Yasin Birey 2019 年 2 月 5 日
You can try to use the last minute of the current day, since it says starting date must be before than ending date
todayDate = datetime('today');
todayDate = todayDate + minutes(1439);
[datetime('today')-days(0),todayDate]
  4 件のコメント
Guillaume
Guillaume 2019 年 2 月 6 日
Well ok, it does create a datetime with a different display format. If that's the whole purpose of subtracting 0, then I would say it's a bad idea. First, you're relying on undocumented behaviour, so that may change in a future release without notice. Secondly, if you want a specific format you'd be better be explicit about the format you want. So even though, 'Format', 'dd, MMM, yyyy HH:mm:ss' might be longer, it's at least very clear what the intent of the code is. Subtracting 0 just to alter the format, with no comment explaining what the purpose is, is just asking for a bug to be introduced later on when a different maintainer notice that 0 subtraction and remove it.
In this particular case, where the array is just passed to another function, the format does not matter at all.
Yair Altman
Yair Altman 2019 年 2 月 6 日
編集済み: Yair Altman 2019 年 2 月 6 日
I echo Guillaume's comment.
However, just for the record, it is typically faster to subtract a pure number rather than days(number). For example,
datetime('today')-1
is faster than
datetime('today')-days(1)
and yet has the same meaning/result. Just note that days(1) might be more readable.

サインインしてコメントする。

その他の回答 (3 件)

KSSV
KSSV 2019 年 2 月 5 日
thedates = (datetime('today')-days(3):datetime('today'))'

Mark Clark
Mark Clark 2019 年 2 月 6 日
This is what Im trying to do. The today trace in the graph below.
CaptureAGT.PNG

Mark Clark
Mark Clark 2019 年 2 月 6 日
See https://thingspeak.com/channels/569794

コミュニティ

その他の回答  ThingSpeak コミュニティ

カテゴリ

Help Center および File ExchangeRead Data from Channel についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by