Welcome to Intermediate Python. This is the second course in Python scripting for DevOps specialization. In this first module, we want to think about dates and some more advanced string operations. By the end of this module, there are several things I'd like you to be able to do. One is I'd like you to be able to develop computer programs that utilize the string operations in the execution of a program. Next, I want you to be able to develop computer programs that utilize date and time data types in the execution of a program. You should also be able to develop computer programs that format numbers. Lastly, you should be able to develop computer programs that format dates and times. In this first lesson, we're going to look at dates and time values. Python has a DateTime module. To create a date, we can use the datetime constructor of the datetime module. The datetime class requires three parameters to create a date: the year, the month, and the day in that order. I've a little sample here. We'll import the datetime and here I'm just assigning the return value from the datetime datetime constructor for February 26, 2021. I'm going to sign that back to x. The datetime class can also take an additional parameter. It requires five parameters to create a date and a time. In this example, I'm importing datetime and then I'm creating a variable, I'm naming it x. That's going to be February 26 of 2021 for 2:00 in the afternoon at 22 minutes after 2:00. We also have two very valuable functions. One is strftime, and the other is strptime. Both of these will use the same format codes. In front of you I'll show you the format code is column one, column two is the meaning, column three is the example. All the examples are generated from a date that I created with the datetime constructor of September 30th, 2013 at 7:00 in the morning, six minutes after and five seconds after that. Do you see the constructor at the top of the screen in front of you? I'm not going to read all of these to you but let's look at some of them. The percent lowercase a shows the weekday as whatever it is in that locales abbreviated form. In my locale, we abbreviate Monday for example as Mon with a capital M. A percent uppercase a will show the full name. In my example, it's Monday spelled out. Hopefully you're starting to get this at this point. A percent w is going to give you the weekday as a decimal number where zero is Sunday and six is Saturday. Monday, again in our example is one. There are several others in front of you. You can see percent d gives you the day of the month as a zero padded decimal number. If I put a negative sign between the percent and the d, I'll get it just as a single digit if it's a single digit, depending on your platform. There's ways to spell out the month with the b's, both in abbreviated and full form. We can have the number with a lowercase m for the month and the year, either the year as a two digit or a four digit. We've got the hour, either as 24-hour clock or 12-hour clock. We can add AM and PM and then we've got our minutes. There's more formats than just these, these are just the most used ones. Here's some more formats. We got the seconds, microseconds, offset from UTC, that's Universal Time Zone and some others. I'll let you read through these here and I have some readings up in Coursera for you to get into some more details. strptime is going to return a datetime corresponding to the string parsed in, parsed according to the format. We just saw all those codes. I've got an example in front of you where we're going to parse in a date string and that date string is November six at 4:30 in the afternoon on the year 2021. You see that expresses 21/11/ 06. That's year, year, month, month, day, day, and then 24-hour clock 16 is four in the afternoon and 30. Then I'm pulling those pieces out based on the codes we just looked at on the right-hand side. Again, that's going to return a datetime value. Next I want to look at returning the current date and time. If you import datetime, in my case here I'm spelling it out. I'm saying datetime.datetime.now, you could just say datetime. now once you've imported datetime, but this is more explicit. Returns the current date and time based on the system clock that Python is running under. I'm assigning it to x. I'm going to use this in my next example, where we want to actually convert the datetime value back to a string. strftime will do that for us. It's going to return a string representing the time controlled by the explicit formatting string that you use, that we saw earlier. Here I'm going to use now. strftime and return in a string using these format codes. That's it for lesson one. Just a little review here. Python uses the same format codes to convert a datetime to a string and from a string, which is nice. Once you learn those codes, you can go either direction. Using the format string, you can pull any part of a datetime value out. The now method returns the current date and time based on the system clock of the computer running Python. I'll see you in the next lesson.