Our next data type is called datetime. So, before I hit the Enter key what information would you guess is stored in an object of the type datetime? I'll give you a few seconds to think. Okay, time's up. If you guessed a date and a time then you are absolutely correct and you'll see that you're correct when I hit "Enter". With that revelation, we end the rocket science portion of this segment, but stay with me because in this segment not only will you learn how to use datetime, but you will also learn the answer to the burning question which segment in this course when's the coveted MBS award, most boring segment. Spoiler alert, it's a tie between datetime and new string. Note how I'm violating the rule of effective teaching that says that I should convince you that whatever I am teaching is fascinating. Okay, but that rule sometimes conflicts with the other rule of good teaching, the rule that says "I should be honest with my students." I'm going with a second rule. Let's us get started because I'm already getting sleepy. So, we've started here with the function that has the same name as the type datetime. When you call it without an argument, the way we just did, it reads your computer's calendar and clock and returns the date and time as an object whose type is datetime as this blue label says. Time has three parts: hours, minutes and seconds separated by colons. These colons bear no relation to the colon operator, they are just simple punctuation. Matlab displays, not only the value of the datetime object, but the name of the type in an underlined blue font, exactly as we've seen it do for structs and cells. As for those types the datatype name is a live link, it'll pop up a window with documentation on the type when we click it. But instead of reading about it, I'm going to tell you about it so, I'm going to close this. So, now you know the exact date that I'm making this segment and the time right down to the second that I gave this command, or do you? Maybe not, because if you change the date or the time on your computer and this function's output will change right along with it. What you don't know, is that I just set my calendar and clock to a fake date and a fake time just to fool you. So, as a matter of fact, you don't know when I'm doing this segment and you don't know when I gave that command. By the way, I could fool you right down to the microsecond if I wanted because you can change the default display mode for the datetime objects to go out to a millionth of a second. You can make the month come out before the day and even change the language in which the name of the month is given. Just click "Preferences" up here in the Home tab, click the "Command Window". Well, it's already clicked and then change the defaults and the datetime format. If, for example, you want to imagine that you were in Paris or better yet some charming village in Provence like say [inaudible] ,you just type fr_FR and instead of July you'll see [inaudible] I almost forgot, if you want to see microseconds, just add a decimal followed by six s's, right at the end here. After you hit "OK" and type datetime again, you'll get the date in French and the time up to six decimal places and you can even take it up to nine decimal places because times are maintained nanosecond precision. Okay, let's set the format back to the default and we'll go from there. So, you can also call datetime with an argument like this. I think it's intuitive what you should get, yesterday gives you yesterday's date, today today's date and tomorrow tomorrow's day. All three of these time points are determined by the computer's clock. By the way Matlab's name for any one of these arguments, is relativeDay and it provides one more relative day that I'll show you in a minute. That's all though, you can't ask for the day before yesterday or my wife's birthday, which would really be good for me. Now that both of these are out of the option lists but that's not a problem, right? This is Matlab, it's dead easy for you to write your own functions for both of these. While you're at it, it's probably a good idea to include mother-in-law's birthday. Speaking of leaving things out, I'm calling this time point but where is the time in these outputs, we got a time before. Well, when you ask for yesterday, today or tomorrow the Math works programmers figured that you're not being specific enough to include a time, so it leaves them out. On the other hand, if you use this fourth and final so-called relative day, they consider the "now" means not only today but this very hour, this very minute and this very second. They give all that to you. Of course that's exactly what we got up here when we call the function with no arguments. So, how would you use this function? Well, you use it when you need to write your own function that includes automatic documentation of the date and or the time. Let's look at a function that does that. I've written a function called open-webpage, over here. It lets you open a web page, I'm going to make some room to show it to you. There, But let's run it first. Then we'll look inside it. As you can see, the function's prompting me to enter the URL that I want to visit. I'm going to type in cs103.net. This particular web page is one that Akash and I maintain for this course and you can use it to get directly to our videos by clicking right here on "VIDEO LECTURES" and then scrolling down here and picking a lecture that you want to see. I don't know, we're using functions through "Introduction to Functions". Nice little cheery introduction. Welcome to Lesson three. Oh my gosh, who is this guy? So far what we've learned is how to perform individual operations with MATLAB and we've used MATLAB as a glorified calculator. Yeah, we learned a lot. Now, it's time to start programming. We haven't learned how to iron our shirt, have we? Do you remember that we call a few MATLABs built-in functions? For example- How come his arms keep stretching out? Calculate the sign and to do other things. Here they go again. Hundreds more functions that will occur. Yeah, hundreds of functions. It's not provided by MATLAB. Guess what? Guess what? Oh, yeah. We can use them just as if they were [inaudible]. Okay. Enough of this guy. Let's see how. Let's close this browser. Oh, look at this. Look at the function printed here in the command window. It says that at such and such a day, and such and such a time, you open a web page at such and such a URL, and it gives us a cheery little, "Have a great Saturday." This is an example of what I was talking about when I said your function can include automatic documentation complete with date and time. Then to end on a very friendly note it wishes us a great Saturday. So now you know that I'm so devoted to your education that I'm working on this video for you over the weekend. Or am I? Maybe today is actually- I don't know, Monday. I've changed my computer's date to a Saturday. Well, whatever date it is and I'm not telling, it's time we looked inside this "function" to see how it works. First of all, it uses the "input" function right here to request the URL from the user. You might notice that the input arguments, either the URL and S are both of the "char" type instead of the "String" type. That's because as a version 2018A, the string type does not yet work with this function. If you have a later version, it might work for you. But here in August 2018, we're not there yet. This second argument, this "S" tells input that the user is going to type in characters with no single quotes or double quotes. It will then automatically put whatever characters the user types up to but not including enter into a char vector, which will be returned by the input function and assigned to the variable named URL here. Next, it checks to see if URL is empty, which means that the user didn't type anything and it'll quit, this return function does that. But if it doesn't return, then it uses date- time to get the date and the time and stores it into the variable search time. Next, it calls the function "web" with the string inside URL, which is a char vector because that's what input returns. However, unlike the antiquated input function, you can give a string to web and it'll work just fine. We then check the status return by web to see how well things went. This status does not tell us whether the web pages found, it just tells us whether the web browser could be run. Zero is good news. It means that the web browser did run. With that good news, we print out this message that says "You open the web page at the search time." Of course, that's hidden behind the web page so you don't see it until you close it, or of course, move the web page window. If status is anything other than zero, that's bad news. Then we print out the bad news message here "Could not start web browser." Notice that we've used the modern string input instead of char input for this F print F, and this F print F, and this F print F. Next, to determines the day of the week. To do that, it uses a function called "weekday" on this line, which returns two output arguments. The first one is an integer from one to seven that gives the number of the day of the week, with Sunday being number one, which agrees with the standard in about half the world. If your country uses Monday or Saturday as the first day, don't worry because this function doesn't use that argument anyway. That's why we have this tilde here. Tilde tells MATLAB to throw that argument away. The second output argument is the name of the day of the week in the form of a string, and that's what we want. We save it in the variable named weekday underscore name here, and we'll use it in this print F function. But what about the input arguments? There are two of them. It gets its date from search time. The second argument tells it to spell out the name of the day of the week instead of giving an abbreviation for it. That's long format. So, we'll get S-A-T-U-R-D-A-Y instead of the abbreviation SAT. Then, finally, here in this print F statement, which again uses the brand new string format, the function prints a cheery little message telling us to have a great Saturday. So, that's how this function uses the date-time data type, but there are many other ways to use it, and there are many more functions for manipulating this data type. Let's get a list of them. You remember how to do that from the previous segment? Type "document command window", click "MATLAB", click "Language Fundamentals", click "Data Types", click "Dates and Time", and click" Expand All" if you want to see a whole list. There they are. Each of these links will take you to a help page for one function, and there are a lot of them. Again, I'm not going to go over all the functions in the list. I do have a few more things to show you but once you've gotten an idea of what's involved with this data type or any data type and you know how to get a list of links to the help pages for all the functions that are specially designed to manipulate objects of the data type, you can do anything with it than I can, and you don't need me to do it for you. It's like the old saying goes "Give me a fish and I eat for a day. Teach me to fish and I eat for a lifetime." As we click through these documentation pages, you've learned how to fish for useful data types. We've already used date-time. See here. So, I can click on that and you can see something here interesting below it called NAT. That means not a time or for that matter, not a date. It's like NAN which you'll remember is a particular value of the double type that means not a number. I'll now, MATLAB is added NAT is a special value of the DateTime type to me not a time. You can use this value is an element of an array of date times to indicate that this element has not been entered or is not yet known or something like that. But I want to move on to these so-called Duration functions here which create objects whose type is called a duration. Each of these functions return an object that's a little different from a DateTime. A DateTime object represents a particular point in time like 2:30 PM, is afternoon. But a Duration object represents a length of time like two and a half hours. Well, let's take a look at that. We'll get rid of this page first and let's use the hours function. Here's how you get a duration of two and half days. There's something big going on here in MATLAB's display of these duration values. It's not the word duration which gives the type and that good old underlined blue bold font which we've seen before. Now, the big thing is something entirely new. It's the inclusion of units of hours indicated by the abbreviation HR and days. When have you ever seen MATLAB use units? As we pointed out, what seemed like an eternity ago in lesson one, when we were talking about using MATLAB is a calculator. There's no way to specify units for ordinary numbers, double, singles in your dates, et cetera. So, if you calculate the speed of light, MATLAB can't tell you whether the result has units of meters per second or miles per hour or for that matter, pounds per square inch, is just a raw number, but Duration objects are different. We'll see other units show up and other duration examples below. So, we know what a duration object is and we know that they have units, but what can you do with them? Well, for one thing, you can add them to DateTime objects. You can subtract two like this and these three examples, we've used addition with the year's function to get a date three years in the future and used addition and subtraction with the day's function to get dates three days in the future and three days in the past. In each day, the time remain the same, but you can add or subtract hours, minutes, seconds, or milliseconds to change the time, I'll let you try that yourself. I'm going to clear the Command Window and get more space. But before I do that, while a years and days functions are still on the screen, it's a good time to point out that the names of the two functions years and days and also their sister functions, hours, minutes, seconds, and milliseconds are plural. They've got an S on the end. You'll need to remember that because there also functions with singular versions of these names, like day, year and second that have very different meanings, will get into them in a few minutes. For now though, I'm just warning you that it's easy to trip over the plural versus singular difference. Have done it many times. Okay. Let's clean up and give more room. Adding and subtracting is not the only way to get dates in the distant past or future. The DateTime function also takes arguments that can get you any point in time you want directly like this, big event in Berlin on that day. It was a big event for the whole world when that fiasco is finally torn down, but at least it made it obvious how bad an idea border wall is and it made it unlikely that that mistake will ever be made again. It should also be obvious that the three arguments that I gave DateTime are year, month, and day, and you can get any point in time you want. Here I've given six arguments and you probably noticed from that little popup that the last three are hour, minute, and second. The armistice to end the fighting in the First World War was famously signed in 1918 at the 11th hour of the 11th day of the 11th month. But who's 11th hour? I say that because if you look around the world, it may be 11 o'clock at one place but five o'clock and another place. Well, that was signed in London and we can set this DateTime to be specific to London's time zone. To set the time zone, we first have to find out what London's time zone is. Time zones are managed worldwide by the Internet Assigned Numbers Authority, which is best known for assigning internet numbers, that should keep them busy but they handle time zones in their spare time, you can look all add up. The MATLAB saves you the trouble by providing a handy function called time zones, which opens a web page in the same way that our little open web page function did. Now to define what we're looking for, we click on the little search icon over here, it's like binoculars. Then we type London into the search box, and there's what we're looking for, the name, Europe/London. We can now close this site and set the time zone property of our DateTime variable to the string Europe/London. We do that by using the dot operator. This is the same dot operator that we use to set fields and structs like this. Nothing changes because there was no time zone set for this variable before. Let's make a copy of this variable. Copying a variable copies everything in it, so it's time zone property is copied to as we can see if we query it. Now, if I adjust this new variables time zone property to correspond to say, Nashville, which is in a different time zone from London, we'll see a change. Despite the worldwide fame that this Mooc has brought to this city of Nashville, it hasn't been quite enough to earn us a coveted spot in the IANA a list. But, we happen to be in the central time zone with Chicago which has made it into the list and I happen to know it's time zone name. So, we see that it was 11:00 AM in Nashville and Chicago when the Armistice was signed. The minute and the second aren't important as far as I know. They're not even known. So, why did I include zero minutes and zero seconds up here when I specified Armistice_WW1 was 1918 11 11 11. Well, if you're going to give an hour, yeah, I have to give a minute and a second too. This is what happens if you don't. So, I've given the year, the month, the day, and the hour. We get this message, error using DateTime line 581. Numeric input data must be a matrix with three or six columns or else three, six or seven separate numeric arrays and then it tells us another way to do it. Well, we put in separate numeric arrays which happened to be singletons. But we put in four of them which makes sense if you don't know the minute and the second. MATLAB could easily have accepted this input and filled in the zeros for the missing values, but no, they couldn't do that, they'd rather send us this big long harsh message. Okay. My Get a grip. Anyway, this.operator which we used here, here, and here reveals that these datetime variables are implemented as structs. Since a datetime variable is implemented as a struct, you can use the function called field names to see all its fields. Because of the way we're using in looks like a struct, but it's definitely not a struct. It's still a datetime, it just uses the.operator to access its properties and the field name function to see their names one of which is TimeZone. These property names are fixed and they're case sensitive and you can't add new fields the way you can for a struct. These eight are all you get. The fighting stopped on the day of the armistice was signed but the official end of the war had to wait until the peace treaty was signed which in turn had to wait until the leaders of the countries involved had completed their required 228 days of squabbling. my goodness, this is turned into a history lesson. What was I talking about? Oh yeah, MATLAB. We've added 228 days to November 11th and that puts us June 27th. What happened with the time? Why did we end up at noon instead of 11 AM? Can you guess? Daylight savings time. It went into effect in Europe in the spring in 1916. The US started in 1918 and stopped it than did it about it turning it off and on and letting it vary from state to state for 89 years until 2007 when it became uniform across the country. Fortunately, for us though MATLAB takes care of adding the daylight savings time our for us. So, we don't have to deal with that irritating detail ourselves. That's a great advantage thank you MATLAB. It's a great advantage indeed when the time of day is important, but in the case of the Treaty of Versailles it's not because nobody took any special notice of it. So, we shouldn't show any time at all for the treaty signing. We just want the date, where you can get rid of the time by using another property and the list above, the format like this. You can use the format property to do a lot more than simply omitting the time, you can change how the datetime values displayed too. For example, maybe you like this short format day, month, year. Don't forget to use uppercase for MM, because lowercase means minute. There are 40 plus formats that you can put together in millions of combinations and you can find all of them in the datetime documentation page by scrolling down the properties and looking for format, and in that list if you prefer very long format you'll find all this. The four Es gives you the day of the week. Thanks to it we now know that the Treaty of Versailles was signed on a Friday. Talk about TGIF, but that's enough history. Let's get back to those functions called day, year, minute, and so forth that I was warning you not to confuse with the plural versions that we used before like years which if you don't remember it works like this. There couple of interesting things here. First, there's a 100 year anniversary coming up next June. Second, the anniversary will be on the 27th but for some reason we got June 26. Why does our calculation off a day? Well, the reason has to do with leap years. The function years treats all years is having the same number of days 365.2425 which is the length of a year averaged over four centuries, or the actual number of days in a year is 365 except on leap years in which the leap day February 29th is inserted into the calendar. So, while years agrees only average with the calendar it does not agree exactly for every year. Fortunately, MATLAB has that issue covered too. To get exact agreement, just use the function calyears which means calendar years. It'll keep up with the entire leap year schedule for you. Now, you can mark your calendar for the big celebration. How do you celebrate the end of a war? Maybe by fireworks and the note send them off. Anyway you can see from this how important calyears is and there are other calendar functions too such as calmonths, calweeks, and caldays, and calquarters. But maybe you could just look those up in the datetime documentation because we need to get moving. Oh my gosh, do you realize how many side structs we've gone down while the singular functions have been waiting to get onstage? Don't you just love a good mixed metaphor? I mean, we had to get through TimeZones, daylight, savings time, formats, and leap years for goodness sakes. But we're ready for him now. To make sense of them, it might help to know that these functions which are named year, month, week, day, hour, minute, second, and quarter are very old functions. That had already been around at least eight years when the datetime and duration types were added in 2014. Those old functions were originally part of the library for handling problems in finance, which like engineering is a big application for MATLAB. Those old timers were immediately updated to accept the new datatypes as input arguments, but at the same time the language designers saw a need for some new functions that also dealt with years, days, hours, minutes, and seconds. These new functions had to have different names so they made him plural. So finally, let's see what these functions do, and there's minute, and there's second too. In the datetime documentation page, you'll find these functions under the heading split dates and times because as these examples show they split off parts of the datetime. You can even determine which one of the four quarters of the year the date occurred in. You got to be able to do that because those financial folks are preoccupied with quarters for some reason. These split functions are pretty simple really but if you forget how they work and try to get information from the help function there's a little problem you should know about. Let's say we ask for the year function. At least this is what I get and it should be similar to what you get if like me you have an installation of MATLAB without the financial toolbox. Is not very helpful because it doesn't explain what the function actually does and what does tolerate mean? Well, that's an advanced subject but tolerates can come in handy if you have an application that works with so-called big data, because it allows you to set up arrays with hundreds of millions or even billions of elements despite the fact that they won't fit in your computer's memory. But in any case this is where help takes you when there's no financial toolbox installed. On the other hand, if you've installed the financial toolbox, or if you're using MATLAB online which always has all the toolboxes, you'll end up in a different room of the documentation with the help page it's even less helpful because it gives wrong information about what the function does at least it's wrong if you want to know what it does with the datetime object which is what we want to know. No matter which of these two rooms you find yourself in, here's how to get into the datetime room. Just look for the message see also and the blue link named datetime/year or if your installation doesn't show that link, look for a blue link named other functions named here, click on that and a linked labeled datetime/year should appear. Either way click on this link, go through the two doors in front of you to enter the hyrule castle kill Gandalf with the Master Sword. Now, I've gotten off track a little bit here. You're actually there, you're quest is over you've won the game. As Victor your final reward is to get to see what the function does, and what its inputs and outputs are. So that's that. Let's get out of here, this place with all its secret passageways and everything is spooky. So, we finally learned how to use the functions year, day, hour, et cetera which split out parts of a datetime object. We've learned the secrets of capturing their help pages deep inside MATLAB's documentation cave of wonders. But guess what? There's another way to split out that information and you've already seen it. Remember this, where you can get the year, day, and hour of the armistice with the fields year, day, and hour like this. Just don't forget to capitalize those field names. If that's not enough, you can look up the functions ymd which means year, month, day, and hms which means hour, minute, and second. In every case, the values you get back from these many splitting operations or doubles. None of them will give you a duration object. The only way we've seen to get one of those is to use a plural function like years and days, but there is another function that will give you a duration and its name is pretty easy to remember, duration. Let's see, its inputs game works like Datetime except that it starts with hours instead of years. These inputs are three hours, seven minutes and 43 seconds. The output is the same but it's printed with colons to separate them instead of commas like the datetime. Again, these colons are unrelated to the colon operator. You can even give a fourth argument which contains milliseconds. I always want to know how long my movies are down to the millisecond. What can you do with this duration? Well, for one thing, you can do arithmetic with it. Want to know what half of three hours, seven minutes and 43 seconds is in terms of hours, minutes, and seconds? Nothing could be easier. One hour, 33 minutes and 51 seconds. You can multiply, subtract, and add too. Wow! That would be a long movie, and this last example is the most interesting one. It uses mixed mode arithmetic, meaning that we have two different types as input to the arithmetic plus. The two different types are duration and double. First off, the type of the result of the operation is duration as we can see here instead of double and that's what we wanted. So, that's good. The more important thing about this example is that we've added one to the duration and it went up by 24 hours, from three up here to 27 down here. That's revealing. It means that the basic time unit of duration is the day. It's also the basic unit of Datetime. That's a common thing. Microsoft uses day as its unit in Excel Spreadsheets for example. So, that gives me a great idea. If the basic time unit is the day, then a duration must be stored as the number of days. So, we should be able to see the number of days in a duration by converting the duration to a double like this. Another great idea shot to heck. MATLAB just won't do it. It tells us instead that if we want to convert a duration to a number, we have to do it with the seconds, minutes, hours, days or years function. So, why do you think that is? Well, it's because there's no way for MATLAB to know what number I want. I want the days but I could just as well if I wanted the number of minutes too or seconds. Here's the number of seconds and here's the number of days which is what I wanted. I've got to know how many days my movies are and while we're on the subject of arithmetic, yet another way to get a duration is by subtracting two date times. Let's do that to find out how long the Seven Years War lasted and I got to clear the screen again. I'm going to be a real neat nick. So, now I know that the Seven Years War lasted 59,160 hours. Let's get that in years. So the Seven Years War should be called the 6.7489 years war. You might want to make a note of that. You know, I probably shouldn't say this but in my opinion, this is an example of just how sloppy these historians are. I'd sure never make it as engineers rounding things off to the nearest whole number then. Let us find out just how far off they are in days. Ninety one days of war that never happened. Stopping early probably saved a lot of lives. Thank goodness the people that actually decided to end the war weren't historians. It's important to note that this subtraction has to account for the number of days in each month. Twenty eight in February, 31 in March, and 30 in April and let's repeat this subtraction for the same dates in the following year 1764. I'm going to copy this previous command from the history with the up arrow and then change each three to a four. There is an extra day. By now you probably know why, 1764 was a leap year. So, its February had 29 days. So both of these subtractions gave us the number of elapsed days and each number is in the neighborhood of 90, but there's something strange in the neighborhood. Where is the word days? Remember how I was talking about how durations have units, hours, or weeks for example, and how it's such a nice feature, and where's the word duration in bold underlined blue letters? Well, days and duration are missing because the type of the variable returned by days was double in both cases not duration as we can show using class. Come to think of it, we saw the same thing happen when we calculated how many days our long movie lasted. But when we first used days, we got the whole nine yards. Well, actually days not yards and it was two and a half not nine, remember this. So, are we losing our minds here? One minute days returns a value of type duration and the next minute it's returning a double. How can a function behave differently from one call to the next like that? Well, it's time for me to bring up polymorphism for the 100th time. This function in its siblings years, minutes, et cetera are polymorphic. The type of their output depends on the type of their input. Your output are durations when their inputs are numbers and their outputs are numbers when their inputs are durations. Okay, that's the rule but the next question is, why is that the rule? Why don't these functions return objects of the type duration no matter what type of input they get? Of course, there are certainly some cases in which we would want to double instead of a duration so we could feed the answer to functions that require the double type. In that case, couldn't we just convert the duration to a double using the double function? Like this. Yeah. I guess I kind of forgot about that. We already explained that double couldn't convert a duration to a number because it doesn't know what units you want. So, that's not going to happen. The solution that those clever girls and boys in Natick, Massachusetts came up with is to have the six functions years, days, hours, minutes, seconds, and milliseconds do the conversions from duration to double and from double to duration. They can do it because the name of each function reveals the units that the user wants, and they can do all 12 conversions with six functions instead of 12 functions named. You know, double to years, years to double, double to days, days to double, et cetera. Well, let's clear the screen again. That's enough arithmetic on Datetimes and durations, but there's a related thing you can do. You can compare points in time using relational operators. Let's do an example of that. First of all let's specify a couple of new points in time. Now let's generate some random days. I'll initialize the random number generator so you can duplicate my results, like that. What I've done here is start at the beginning of the station, go back 30 days, and then with that starting point, I've added five days by calling this random int generator, asking it to produce a five by one column or random numbers selected from one to 100. This is the result, we get a five by one array. Let's see which one of these comes during the session. Now, obviously you can look and see which ones come during the session. But suppose there were a thousand of them, then you'd need MATLAB's help. Now, what I've done here is set during_session to be equal to a logical expression. Here, I've got a relational operator less than or equal, and I'm comparing the start of this session with these five dates. The result will be a column vector, true or false? True, if the start of the session comes on or before the date or to put it in another way, true if the date is on or after the start of the session. Over here, I'm checking to see whether the dates come on or before the end of the session, and I combine this first vector of results with this second vector of results using an element by element and operator, and we get a five by one logical array. True, true, false, true, true, we got four out of five hits. This is our first example of a vector of type datetime. But you can do column vectors, row vectors, you can do two-dimensional and higher also, just as with all the other types in MATLAB. As you might guess, we can do the same thing with duration objects too. Create arrays of them and use relational operators to compare them. For more readable result, you can convert the string as we've seen before. It's just as easy to convert the datetimes themselves to strings, for example, and you can convert durations too. Conversion to string is important when you're building strings that incorporate date and/or time information. Here's a function that uses it to make a one month calendar. Let's get a little bit room so I can see, there. Let's run it and then we'll talk about it. I've given it two inputs, eight and 2018, and that means eighth month and the year 2018, and it gave us a calendar for August of 2018 in the form of a string column vector with 11 elements. This function is available in the reading assignment for the week of this lesson, as are all of the functions listed over here in the current folder, so you can try them and study them yourself. I'll simply point out that this function converts a datetime object dt to a string on third line after it constructed the datetime object on the first line, and then formatted it on the second line. The format determines what comes out in the string. The actual numbers that go into the calendar or gotten from the calendar function, which you can read about in the datetime documentation. As we just mentioned, we use the dot operator on the datetime object dt in this function. In the example before that, we use plus and minus operators with datetime and duration objects, and we've even used multiplication and division. As a guideline for using operators with these types of objects, a good rule of thumb is that if it makes sense, it'll work. There's one last operation that I want to show you that makes sense; the colon operator. Don't worry, I'll make this short. Let's just dive into an example. In this colon operation, we put datetime objects at the beginning and at the end, and a duration object in the middle. To answer the burning question: How many 4th nights were there in 2018 from March 27 to May 13th? As you can see, there were one, two, three. Last one started April 24th and ended May 8th. There's another way to get a sequence of datetime objects. You can use a double for the increment like this. I'm going to be lazy and just edit the previous command. There. As you can see, this double is treated as a number of days, we get exactly the same result. You can get a sequence of duration objects using the same idea. Here again, putting a double n gives you a number that's treated as days. Okay. Finally, and that's finally as in finally all this datetime stuff is about to be over, you can use datetimes and durations and plots. Look, I know you're sleepy and tired, heck, I've drifted off five times as myself while I've been talking to you. But we're almost done and this plotting business is fun anyway and easy. We'll be done in the jiffy because MATLAB has made plotting with datetimes and durations so simple. I've got some data in my workspace, it's been waiting all this time to be plotted for you. So, let's haul it out and take a look at it. It's a set of times and heights for the tides at Santa Belle Island in Florida. That island is one of the great places in the world to find shells, and the shelling is best at low tide and worst at high tide. So, it's important to shellers to know how the tides change over time. There are roughly 120 tides per month in Santa Bell and most places for that matter, alternating high and low, and I've got a month's worth of them right here. Let's look at the first 16. So, we've got 16 datetimes and we got 16 heights, these are in feet. So, we see on the 1st of August at just two minutes after 4:00 AM, the tide was at 2.25 feet, and then at 10:03 AM, it had dropped to 1.25. So, that's a high and a low and there is a high low, high low, high low and so on it goes. It's about four a day as you can see on August 1st and August 2nd. On August 3rd there's only three but the next one happens just past midnight. Well, you can look at all this data and try to make sense of it, but there's nothing like a plot. My goodness, it still looks pretty complicated. Like maybe there are two superimposed patterns, one with big swings and one with little swings. But at least, the plotting is simple. The plot function works the same with datetime vectors as it does with any other vectors. You just give it two vectors like this with the same number of elements. In this case, a 120 each and it plots one against the other, and we can examine the plot as usual. I'm going to stretch this one out horizontally. Click Tools and Options, Horizontal Zoom and then stretch the plot out horizontally with my mouse wheel. As I do that, you can see that these are not overlapping graphs of big swings and small swings at all, but there is actually a high tide and a low tide, then a little high tide, a little low tide, and then a high tide and it repeats and repeats. Let's see how far apart these are in time. Here's a low tide at about 6:00 PM and a little one at about midnight. Then, another one little low tide at 6:00 AM and then at noon, and another high tide. So, these things are swinging back and forth about six hours apart. This pattern is duplicated with some variation at every coast in the world. It's caused by the interplay of the Moon, the Earth, and the Sun, and with some secondary effects caused by local land shapes. The guy who figured all this out for the first time was Isaac Newton, but you'll need to find a course on physics and astronomy to really understand that. Fortunately, you don't need all that for shelling, you just need to look at the plot. Let's do another plot for the shellers. With this one, I'm going to use separate vectors for the high and low tides and plot them in two different colors. Close by the way, close as the figure. Let's decorate our plot with a title and a label for the y-axis and we'll add a grid. Well, the figure is hidden by the desktop because it comes to the front, that is the desktop comes to the front when you click in it. I can bring the figure back on top like this and there it is. Now, we can see the high tides up here in blue and low tides below them in red. It looks like the 10th and 11th of August was some primo shelling. Zero by the way is the average low tide for the region. It's averaged over 19 years by the National Oceanic and Atmospheric Administration which provides the historic and predicted tide data from which I got these plots. Well, that's it for plotting and we've at long last reached the end of our segment on datetime and duration objects. That's also the end of lesson seven. That's a good thing because I am worn out. Don't worry, I'll be back again in less than eight, all rested and ready to go and three years younger. See you then.