covert julian date to calander date

瀏覽次數:40 次
跳到第一則未讀訊息

sum abiut

未讀,
2016年9月19日 晚上7:42:292016/9/19
收件者:django...@googlegroups.com
Hi,
how to you convert from Julian date to a Calender date. I am pulling data from an MSSQL and i what to convert the Julian date to calender date before displaying data on my template.

cheer

C. Kirby

未讀,
2016年9月20日 凌晨3:11:422016/9/20
收件者:Django users
I've never used it, but this package appears to be made for converting between Julian and Gregorian dates
https://pypi.python.org/pypi/jdcal

Good Luck

Erik Cederstrand

未讀,
2016年9月20日 清晨6:23:202016/9/20
收件者:Django Users

> Den 20. sep. 2016 kl. 01.40 skrev sum abiut <sua...@gmail.com>:
>
> Hi,
> how to you convert from Julian date to a Calender date. I am pulling data from an MSSQL and i what to convert the Julian date to calender date before displaying data on my template.

If I understand your question correctly, that should be easy. Just convert the Julian date to a Python date in your view:

my_date = (datetime.datetime(my_year, 1, 1) + datetime.timedelta(days=julian_day)).date()


Erik

sum abiut

未讀,
2016年9月20日 晚上8:42:562016/9/20
收件者:django...@googlegroups.com
Thanks Erik,

i think that should do the trick.is there a way to covert the date column straight from the sql query or from the template?

cheers




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/236EFE25-2F80-4247-9972-56DF60C662AA%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Erik Cederstrand

未讀,
2016年9月21日 凌晨3:45:142016/9/21
收件者:Django Users

> Den 21. sep. 2016 kl. 02.41 skrev sum abiut <sua...@gmail.com>:
>
> Thanks Erik,
>
> i think that should do the trick.is there a way to covert the date column straight from the sql query or from the template?

If you want to do this from the template, create a custom template tag: https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/

I don't have experience with MSSQL, but if you want to convert the date server-side, this should work: http://blogs.msmvps.com/robfarley/2009/03/25/converting-to-and-from-julian-format-in-t-sql/ You could add the custom SQL as a RawSQL: https://docs.djangoproject.com/el/1.10/ref/models/expressions/#django.db.models.expressions.RawSQL

Depending on how your data is represented, you could also solve this with a custom model field: https://docs.djangoproject.com/en/1.10/howto/custom-model-fields/ The conversion code should go in the from_db_value() method.

Erik
回覆所有人
回覆作者
轉寄
0 則新訊息