โ01-07-2023 07:04 AM
how to add a current date after filename suffix while copy from the dbutils like report20221223.xlsx
โ
dbutils.fs.cp('dbfs://temp/balancing/report.xlsx','abfss://con@adls/provsn/result/report.xlsx',True)
โ
i need to add the current date in the file like report20220123.xlsx while copying from source to target location
how can we add a current date after the suffix in filename while using dbutils.โ
โ01-07-2023 09:03 AM
@Mohammed sadamuseanโ hope the below code might help you,
from datetime import datetime
date_value = datetime.now().strftime("%Y%m%d")
src = 'dbfs:/FileStore/Test/File.csv'
trgt = f'dbfs:/FileStore/Test/File_{date_value}.csv'
dbutils.fs.cp(src,trgt)
Happy Learning!!
โ01-07-2023 07:40 AM
This will give you a little bit more idea
import time
timestr = time.strftime("%Y%m%d-%H%M%S")
print(timestr)
Now you can use formator and implement this solution
Thanks
Aviral
โ01-07-2023 09:03 AM
@Mohammed sadamuseanโ hope the below code might help you,
from datetime import datetime
date_value = datetime.now().strftime("%Y%m%d")
src = 'dbfs:/FileStore/Test/File.csv'
trgt = f'dbfs:/FileStore/Test/File_{date_value}.csv'
dbutils.fs.cp(src,trgt)
Happy Learning!!
โ01-10-2023 04:34 AM
how can we get the data without hyphenโ
โ01-10-2023 05:44 AM
You can try like below
from datetime import datetime
datevalue = datetime.now().strftime("%Y%m%d")
src = 'dbfs:/FileStore/Test/File.csv'
trgt = f'dbfs:/FileStore/Test/File{datevalue}.csv'
dbutils.fs.cp(src,trgt)
Happy Learning!!
โ01-10-2023 03:21 AM
Hi @Mohammed sadamuseanโ, We havenโt heard from you since the last response from @Aviral Bhardwajโ and @Ratna Chaitanya Raju Bandaruโ, and I was checking back to see if their suggestions helped you.
Or else, If you have any solution, please do share that with the community as it can be helpful to others.
Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group