mssql date format

Nathan Ernst nathan.ernst at gmail.com
Mon Sep 12 21:50:47 EDT 2016


Note that this issue is mentioned in the pymssql FAQ:
http://pymssql.org/en/stable/faq.html#pymssql-does-not-unserialize-date-and-time-columns-to-datetime-date-and-datetime-time-instances

Regards,
Nathan

On Mon, Sep 12, 2016 at 8:29 PM, Dennis Lee Bieber <wlfraed at ix.netcom.com>
wrote:

> On Tue, 13 Sep 2016 00:52:59 +0100, MRAB <python at mrabarnett.plus.com>
> declaimed the following:
>
> >On 2016-09-13 00:06, sum abiut wrote:
> >> Thanks for the response,
> >> i pulling data from an mssql database and i need to convert the date
> >> column. how to i covert and pass it to my template. i am using Django
> >>
> >> this is what i did
> >>
> >> conn=pymssql.connect(server,username,password,database)
> >>     #cus=conn.cursor()
> >>     cus=conn.cursor(as_dict=True)
> >>     cus.execute("SELECT
> >> account_code,currency_code,balance_date,debit,credit,net_
> change,home_net_change
> >> FROM glbal where account_code= '50101001CORP'    ")
> >>
> >>     return render_to_response('revenue_budget.html',locals())
> >>
> >>
> >> how to i  convert the balance_date with the code below:
> >>
> >>
> >>
> >>             import datetime
> >>             datetime.datetime.fromordinal(733010)
> >>
> >> datetime.datetime(2007, 11, 30, 0, 0)
> >>
> >>
> >The documentation for pymssql should tell you how to get the values of
> >the fields.
> >
> >In the case of the 'balance_date' field, just pass its value into
> >datetime.datetime.fromordinal like the code I gave.
>
>         I have a suspicion the OP needs more basic help than that -- like
> how
> to take data from the database, modify it, and pass it on to Django for
> rendering. Note that the sample code never references records from the
> cursor, and seems to just dump [locals()] everthing into the response
> template.
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>     wlfraed at ix.netcom.com    HTTP://wlfraed.home.netcom.com/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list