0

I am trying to fetch a date from sqlserver2008 convert it into milliseconds and use it in my code. This is my code

cursor.execute("select min (d.Date) from (select ProdID as brand ,max(Datekey) as Dt from SocMet_Daily_Fact where ProvID=5 group by ProdId) a left join dimdate d on a.Dt =d.DateKey")
    from_date=cursor.fetchone()
    print "printing from_date type"
    print str(type(from_date))
    from_date=parser.parse(from_date)
    print from_date
    from_sec=time.mktime(datetime.datetime.strptime(from_date, "%Y-%m-%d H:%M:%S").timetuple())
    from_sec=int(from_sec*1000)
    print from_sec 

I get this response/error.

 printing from_date type
    <type 'pyodbc.Row'>
    'pyodbc.Row' object has no attribute 'read'

Is my parsing correct?Is this the correct type of parsing to convert a DB row object into a date type object?

Note that in the database the row is in this format

2014-07-01 00:00:00.000
0

1 Answer 1

1

try giving from_date[0]. since your from date is sql queryresult and min(date) is present first element

Sign up to request clarification or add additional context in comments.

3 Comments

Used this line from_sec=time.mktime(datetime.datetime.strptime(from_date[0], "%Y-%m-%d H:%M:%S").timetuple()) and I encountered this error: printing from_date type <type 'pyodbc.Row'> (datetime.datetime(2014, 7, 1, 0, 0), ) <type 'pyodbc.Row'> must be string, not datetime.datetime
@user1841772 try str(from_date[0])
Thank you.How stupid of me! not using str(from_date[0]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.