databricks-date - python

arkiboys 9,706 Reputation points
2022-04-22T08:24:16.773+00:00

in databricks using python:

import datetime
currentDateTime = datetime.datetime.now()
monthNo = currentDateTime.month
mypath = 'container/foldername/'

fullpath = mypath + 'month=' + str(monthNo) + '/day=' + str(dayNo)

Question:
How can I get 0 infront of a single digit month or year?

Thank you

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,514 questions
0 comments No comments
{count} votes

Accepted answer
  1. ShaikMaheer-MSFT 38,546 Reputation points Microsoft Employee Moderator
    2022-04-25T09:59:22.077+00:00

    Hi @arkiboys ,

    Thank you for posting query in Microsoft Q&A Platform.

    You can use string formatter in python to do that trick. f"{x:02}" here x represents your number. Please check below image for your idea.
    196049-image.png

    Below link has detailed discussion on same. Kindly check.
    https://learn.microsoft.com/en-us/answers/questions/821314/date-folders.html

    Hope this helps. Please let us know if any further queries.

    -------------

    Please consider hitting Accept Answer. Accepted answers help community as well.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.