Working with Dates and Times in MATLAB - MATLAB
Video Player is loading.
Current Time 0:00
Duration 2:31
Loaded: 6.52%
Stream Type LIVE
Remaining Time 2:31
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 2:31

    Working with Dates and Times in MATLAB

    In MATLAB®, learn how to utilize the three date- and time-related data types—datetime, duration, and calendarDuration—to more effectively manage and compute with the date and time data many of us work with every day.

    Published: 6 Jun 2022

    Hello, and welcome back to another MATLAB video. Today we're talking about working with dates and times in MATLAB.

    As many MATLAB users know, dates and times are very common in the data we work with every day. Dates and times pop up in a wide variety of information, from financial records to ecological studies. In order to wrangle these pervasive bits of data, MATLAB has three helpful data types for you to use. Date time, duration, and calendar duration.

    Let's dive into the details on each of these data types. Date time is a data type used to represent moments in time. Illustrated by it's variable icon in the workspace, a single day in a calendar. Date time is the primary way to store a date and time information in MATLAB.

    Duration is a data type used to represent a length of time in fixed units. And it's variable icon, a clock, reflects this. You can create them using functions like seconds, minutes, hours, or days.

    Calendar duration is a data type used for any situation that requires variable lengths of time like one month, which could represent 28, 30, or 31 days. It's icon in the workspace, multiple days highlighted in the calendar, embodies this. You can create them using functions like cal days, cal weeks, cal months, cal quarters, and cal years.

    These three data types have much in common and interact with each other often. Dot notation is used to see and adjust the properties of all three, like changing the units of how the date or duration is displayed. Plus, dot notation can be used to assign a time zone to a date time, which is essential when dealing with data from multiple locations.

    Importantly, time zones in MATLAB automatically account for daylight savings time. You can subtract one day time from another to get a duration, and you can add or subtract a duration to or from a date time to get a new date time. Durations can be compared with each other. And date times can be used to make arrays of durations.

    Sometimes, when doing math with durations, you need to know the duration of a particular month since different months have different numbers of days, which is where calendar duration comes in. And finally, you can plot easily using these three data types with the axis is formatted when the plot is created.

    In this video, we have discussed the essential data types for working with dates and times in MATLAB. Now that we have a better understanding of how to work with and manipulate date and time data types in MATLAB, you can work more efficiently with all the dates and times present throughout so much of real-world data. Thanks for watching, and I'll see you guys in another video.

    Related Products