 Hello, welcome to SS Unitex, you see this side and this is part 2 of Daytime Function in PySpark. Thanks for your support in previous video. So let's start with today's video. So today we are going to see about these three important functions. The first is the date difference. Second is the month between. Next is the trunk. So what is the real time use of these three functions will be going to see in practical. So here let me try to execute this for creating the data frame that is DF and it is having total two columns. First is the ID and second is the date. If we can expand, we'll see the data type of this as string. So the first thing we are required to convert this into date type. So how we can do that? So for that we have already seen in the last video, we can use DF. Let me try to use with column. In the with column, let me try to use the same column that is date. And here for converting this into date type, we can use the to date function. And inside the to date, we can simply specify this and let me replace the existing data frame with DF. Let me execute this cell and we'll expand. So we'll see the data type of this date column as date. Now the next we are required to check the date difference. So how we can use the date difference function? So for using the date difference, let's assume here we are having these two dates like your current date and this date that we are having in data frame. So how we can check the difference into dates between these two dates so we can use the date difference function. So date difference will be helpful on that scenario. So let me use DF.with column. And here I am going to add a new column may be date.diff. So this will be your column. And for using the date difference, we can use date.diff here. And then here it is asking your end column name and comma your start column name. So the end column name should be your current date. So we can specify current date and then the next parameter it is asking your start date. So start date we are getting from this DF.Date column. Now let me use the DF1 here and here let me use the display of this DF1 and let me execute this cell. So it should be adding a new column that is date.diff and here we are getting the difference between your current date and your actual date. Now the next function we have month between. So how we can use the month between? So for that we can use dot.with column. I am going to add a new column here. And that could be your month difference. Let me put comma. Then we have to specify the function. So function is nothing but month between. So we can use month between and here we are required to pass two parameters. So the first parameter should be your current date and the second parameter should be your date that we are having in data frame. So we will be getting the difference on months. So here we can simply use the current underscore date. So this could be your first parameter and the second parameter should be your DF.Date. Now let me try to execute this cell and we will see the output of this. Okay. So month between is not there. It should be months between. S is missing. That's why we are getting this error. So we are seeing the difference in months. But this is not as expected. We just want to see round off into two digits. So how we can do that? So for that let me copy this and let me put it here. And here let me do the round. So here we can go with round function and at last we can specify comma up to two digits. Let me try to execute this cell. So it should be going to add a new column which has been rounded off up to two digits. Now how we can get the difference into here? So till now we have seen how we can calculate the difference on date. Then we have seen how we can calculate the difference on months. How we can do the round off on months? Then let's see how we can check the difference in years. So let me copy this. Let me paste it here. We want to add a new column. This could be your year difference. So let me use year difference. Here everything will same. But let me remove this round off thing that we have done and let me remove this round function here. So it should be like this. Now here if we can see if we are going to do the difference it will be going to get the difference on months. But for getting the difference into year so this month whatever the difference that we are getting that should be going to divide by 12. If we are going to divide this by 12 we will be getting the data into year. So here we can simply divide this by 12 and let me execute this cell. So whatever the months that we are getting we have divided that into 12. So we are getting this list. But again this is not as expected. We just want to see this rounded off into 2 digit. So we can simply use the round function here and here at last we can specify comma 2. Let me try to execute this cell and this time this new year difference we have replaced the existing one. So here let me try to use the round at the starting. So it should be going to add a new column. So that column should be going to rounded off as we can see into 2 digits. Till now we are good how we can check the difference into date, how we can check the difference into months, how we can check the difference into year and how we can do the round off. Next let's try to see about the function. So before that let me try to use the display of this DF. Let me execute and we will see the output of this and here let's try to see how we can use the turn function. So for using the turn function I am going to add 3 columns. First we will be going to truncate your month and day part. So let's assume if we have requirement we just want to get the first date of the year. Whatever the date we have specified. So we just want to see the first date of year then first date of month. So how we can do such type of scenarios by using the trunc function it is very easy to do that. So let me try to add a new column by using with column and here I am going to use the trunc function with year. So let me try to use the trunc function and it will be going to ask first your column name. So column name is nothing but df.date. Let me put comma. Second it is asking the format. So I am going to truncate this on year level. So let me put this into another data frame that could be df2. Let me use the display of this df2. Let me execute and we will see the output. It will be adding a new column and it has been truncated your month and day. So both has been truncated and it is started of the month. So we have truncate till your year. So the year has been started. So first day of the year we are getting by using this. Let me try to add another column and this time we just want to do the truncate on your month level. So this time your day part will be truncated. So first day of month we will be getting by using this. So here let me call this as trunc month. Let me execute and we will see the output of this. So here first day of month we are getting. If we are going to specify as date so that will not work. We will be going to null because we do not have anything till further to truncate. So let me try to do that so you will be able to understand. So if we are going to specify like day here and here let me use day and execute. So till further we do not have anything to be truncated. So that is why we are getting like this. If we are going to specify the current time stamp here let me try to execute and we will see the output of this. So I hope guys you have understood about it. So the day difference function will be going to get the difference into dates. Month difference function will help us to get the difference between months and year both and the truncation will be going to truncate your month and day from the starting position. So thank you so much for watching this video. See you in the next video.