Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Date format issue
#11
@snippsat I REALLY appreciate your detailed response. I tried adopting your example in my script and received the following-

[INFO] starting cameras...
Traceback (most recent call last):
  File "/home/pi/Public/2Cameras.py", line 64, in <module>
    send_mail(frame=frame)
  File "/home/pi/Public/send_mail.py", line 30, in send_mail
    datetime.datetime(2019, 3, 11, 0, 0)
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
>>> 
This was the code-
def send_mail(frame):

    path = os.path.dirname(sys.argv[0])
    log_file = path + '/email.log'

    # Check if the last email was sent in an 1 minute tolerance.
    # We are going to use a .log file to keep track of it.
    if os.path.isfile(log_file): # First check if file exists.
        with open(log_file, 'r') as f:
            date = '2019-03-11'
            date_to_datetime = datetime.strptime(date, "%Y-%m-%d")
            datetime.datetime(2019, 3, 11, 0, 0)

            if datetime.now() < date_to_datetime + timedelta(minutes=1):
                return

    # Update the email log.
    with open(log_file, 'w') as f:
        f.write(str(datetime.now()))
Reply
#12
Import i use is from datetime import datetime
If just use import datetime then call is like this.
>>> import datetime
>>>
>>> date = '2019-03-11'
>>> date_to_datetime = datetime.datetime.strptime(date, "%Y-%m-%d")
>>> date_to_datetime
datetime.datetime(2019, 3, 11, 0, 0)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 241 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 612 Jan-20-2024, 04:45 AM
Last Post: 1418
  Modifying a date format jehoshua 17 3,003 Oct-29-2022, 08:44 PM
Last Post: jehoshua
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 2,664 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Date format error getting weekday value Aggie64 2 1,426 May-29-2022, 07:04 PM
Last Post: Aggie64
  Convert Date to another format lonesoac0 2 1,676 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Format SAS DATE Racer_x 0 996 Feb-09-2022, 04:44 PM
Last Post: Racer_x
  Date Conversion issue Racer_x 2 1,788 Jan-10-2022, 02:40 PM
Last Post: Racer_x
  How can I compare 2 format of date? korenron 4 1,530 Dec-21-2021, 12:40 PM
Last Post: korenron
  Date format and past date check function Turtle 5 4,265 Oct-22-2021, 09:45 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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