Python Forum
Naming the file as time and date.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Naming the file as time and date.
#1
I have a script that scrapes web data then puts it into an excel file and names it "Results". I'm looking to get the file name to show the current time and date. I'm very new to learning to code and I've had a good go at it myself but I cant work it out without getting errors. Any help would be greatly appreciated.

markets = main("10932509, 7129730, 35, 37, 117, 81, 59, 55, 9404054")
#print(markets)

df = pd.DataFrame(markets)
df.to_excel('Results.xlsx')
Reply
#2
Have a look at the facilities provided by the datetime module: https://docs.python.org/3/library/datetime.html, specifically the datetime class and the following section: https://docs.python.org/3/library/datetime.html.

If you're having problems and getting errors, you need to show all the relevant code and the full traceback.
Reply
#3
You may look also at pandas.Timestamp.now

e.g. check

import pandas as pd
print(pd.Timestamp.now().strftime('%Y_%m_%d_%H_%M_%S'))
print(f"{pd.Timestamp.now().strftime('%Y_%m_%d_%H_%M_%S')}.xlsx")
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Thanks for the feedback. I'll have a good read up and give it another go.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  naming entities(city abbreviations) tirumalaramakrishna 1 398 May-06-2022, 11:22 AM
Last Post: jefsummers
  Wait til a date and time KatManDEW 2 623 Mar-11-2022, 08:05 PM
Last Post: KatManDEW
  Date format and past date check function Turtle 5 1,582 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  Python Style and Naming Variables rsherry8 3 1,430 Jun-07-2021, 09:30 PM
Last Post: deanhystad
  Check last time file was accessed Pavel_47 4 1,767 Jun-01-2021, 05:47 PM
Last Post: Yoriz
  find the header location in a .bin file without reading the whole file at a time SANJIB 0 1,331 Mar-05-2021, 04:08 PM
Last Post: SANJIB
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 1,539 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Update Date based on Time/String stevezemlicka 1 1,370 Jan-08-2021, 06:54 PM
Last Post: Gribouillis
  Confusion about [date]time [formatting] Mark17 0 1,165 Dec-17-2020, 07:25 PM
Last Post: Mark17
  how to change the range of read CSV file every time python file runs greenpine 6 2,724 Dec-08-2020, 10:11 PM
Last Post: greenpine

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020