displaying gregorian date in template

9 views
Skip to first unread message

sum abiut

unread,
Apr 24, 2018, 10:50:59 PM4/24/18
to django...@googlegroups.com
I have a function that query the db and extract and display data on a template


def bydate_display(request):
    if "selectdate" in request.POST and "selectdate1" in request.POST and "selectaccount" in request.POST:
        selected_date = request.POST["selectdate"]
        selected_date1 = request.POST["selectdate1"]
        selected_acc = request.POST["selectaccount"]
        if selected_date==selected_date and selected_date1==selected_date1 and selected_acc==selected_acc:
            convert=datetime.datetime.strptime(selected_date, "%Y-%m-%d").toordinal()
            convert1=datetime.datetime.strptime(selected_date1, "%Y-%m-%d").toordinal()
            engine=create_engine('mssql+pymssql://username:password@serve /db')
            connection=engine.connect()
            metadata=MetaData()
            fund=Table('gltrxdet',metadata,autoload=True,autoload_with=engine)
            rate=Table('gltrx_all',metadata,autoload=True,autoload_with=engine)

            stmt=select([fund.columns.account_code,fund.columns.description,fund.columns.nat_balance,fund.columns.rate_type_home,rate.columns.date_applied,rate.columns.date_entered,fund.columns.journal_ctrl_num,rate.columns.journal_ctrl_num])
            stmt=stmt.where(and_(rate.columns.journal_ctrl_num==fund.columns.journal_ctrl_num,fund.columns.account_code==selected_acc,rate.columns.date_applied.between(convert,convert1)))
            results=connection.execute(stmt).fetchall()


            return render(request,'bydatedisplay.html',locals())

sum abiut

unread,
Apr 24, 2018, 10:57:43 PM4/24/18
to django...@googlegroups.com
Current i have a for loop
<table>
<tr>
<th>Date</th>
</tr>
{% for a in results %}

<td>{{a.date_applied}}</td>

{%endfor%)
</table>

currently the date is in julian date. i wan to convert the date to gregorian date. Is there a way to do that in the template.
--
______________________________________________________________
                                         | Sum Abiut |

Security Blog : Security Tips  | Programming  Blog: Programming

sum abiut

unread,
Apr 24, 2018, 11:11:42 PM4/24/18
to django...@googlegroups.com
i want to do something like
datetime.date.fromordinal(int(date_applied))
to convert date from julian to gregorian date, just wondering it this can be done in template?
Reply all
Reply to author
Forward
0 new messages