question

arkiboys avatar image
0 Votes"
arkiboys asked ShaikMaheer-MSFT answered

databricks-date - python

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ShaikMaheer-MSFT avatar image
1 Vote"
ShaikMaheer-MSFT answered

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://docs.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.


image.png (88.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.