0

I am trying to execute a sql query with Python code and am getting error month muct be in 1..12

I have surfed the net but couldn't find anything related to this issue.

sql = '''
        INSERT INTO {Database}.{Schema}.Instance (
              Id
            , DateTime
            , Period
            , StatusId
        ) VALUES (
            ?,
            CURRENT_TIMESTAMP,
            ?,
            ?
        );
    '''
self['_repository'].execute_query(sql, str(self.id), period, Instance.INITIALISED)

When I am executing the code it gives me an error "month must be in 1..12"

Nick
  • 138,499
  • 22
  • 57
  • 95
Sathya
  • 289
  • 2
  • 9
  • 25

2 Answers2

0
sql = '''
        INSERT INTO {Database}.{Schema}.Instance (
              Id
            , DateTime
            , Period
            , StatusId
        ) VALUES (
            ?,
            CAST(CURRENT_TIMESTAMP AS DateTime)
            ?,
            ?
        );
    '''
self['_repository'].execute_query(sql, str(self.id), period, Instance.INITIALISED)

Can you try this?

arunp9294
  • 767
  • 5
  • 15
  • Same error, 2019-10-31 06:28:33,349 ERROR scheduler.main month must be in 1..12 2019-10-31 06:28:33,349 ERROR month must be in 1..12 – Sathya Oct 31 '19 at 06:34
0

Let me try to help you out.

from datetime import datetime

timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
sql = '''
    INSERT INTO {Database}.{Schema}.Instance (
          Id
        , DateTime
        , Period
        , StatusId
    ) VALUES (
        ?,
        '''
        +
        timestamp
        +
        '''
        ?,
        ?
    );
'''
self['_repository'].execute_query(sql, str(self.id), period, Instance.INITIALISED)
Adam Strauss
  • 1,889
  • 2
  • 15
  • 45