Hi @Shambhu Rai ,
Thankyou for using Microsoft Q&A platform and thanks for posting your question.
As I understand your query, you are trying to retrieve month and year from a date in azure databricks. Please let me know if my understanding is incorrect. I tried to resolve your query using synapse notebook. You can implement the same in databricks as well.
You can use strftime() to convert a datetime object containing current date and time to different string formats.
from pyspark.sql import SparkSession
from notebookutils import mssparkutils
from pyspark.sql.functions import *
from datetime import datetime
var=datetime.now()
print(var.strftime('%Y/%m/%d'))
year = var.strftime("%Y")
print("year:", year)
month = var.strftime("%m")
print("month:", month)
day = var.strftime("%d")
print("day:", day)
For more details , kindly visit : Retrieve month and year using python
Hope this will help. Please let us know if any further queries.
------------------------------
- Please don't forget to click on
or upvote
button whenever the information provided helps you.
Original posters help the community find answers faster by identifying the correct answer. Here is how
- Want a reminder to come back and check responses? Here is how to subscribe to a notification
- If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators