Problem Statement: -
- Get the first name, current date, joiningdate and diff between current date and joining date in months.
- Get the first name, current date, joiningdate and diff between current date and joining date in days.
- Get all employee details from EmployeeDetail table whose joining year is 2013
months_between
datediff()
df_fixed_final.select("First_Name",current_date(),round(months_between(current_date(),"Joining_Date"),2).alias("Diff")).show()
df_fixed_final.select("First_Name",current_date(),datediff(current_date(),"Joining_Date").alias("Diff")).show()
df_fixed_final.filter(year("Joining_Date") == 2013).show()
+----------+--------------+------+
|First_Name|current_date()| Diff|
+----------+--------------+------+
| Vikas| 2024-12-27|142.39|
| nikita| 2024-12-27|131.58|
| Ashish| 2024-12-27|131.58|
| Nikhil| 2024-12-27|131.58|
| anish| 2024-12-27|131.58|
+----------+--------------+------+
+----------+--------------+----+
|First_Name|current_date()|Diff|
+----------+--------------+----+
| Vikas| 2024-12-27|4333|
| nikita| 2024-12-27|4005|
| Ashish| 2024-12-27|4005|
| Nikhil| 2024-12-27|4005|
| anish| 2024-12-27|4005|
+----------+--------------+----+
+----------+----------+---------+------+------------+----------+------+
|EmployeeID|First_Name|Last_Name|Salary|Joining_Date|Department|Gender|
+----------+----------+---------+------+------------+----------+------+
| 1| Vikas| Ahlawat|600000| 2013-02-15| IT| Male|
+----------+----------+---------+------+------------+----------+------+