Skip to content
Discussion options

You must be logged in to vote

Hi, @efornoni
Could you describe what exactly is not working for you?
In what format do you want to write a datetime variable? DATE_AND_TIME or DTL?
If you want to use the DATE_AND_TIME format, here is the code that writes datetime to the PLC and then reads it.

import struct
from datetime import datetime
import snap7


def datetime_to_dat(dt: datetime) -> bytes:
    """
    Args:
        dt (datetime): A datetime object to be converted.

    Returns:
        bytes: A byte string in the S7 DATE_AND_TIME format.

    The byte string has the following format:
    Byte 0: Year (BCD format)
    Byte 1: Month (BCD format)
    Byte 2: Day (BCD format)
    Byte 3: Hour (BCD format)
    Byte 4: Mi…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by gijzelaerr
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #434 on March 19, 2023 11:07.