covert julian date to calander date

40 views
Skip to first unread message

sum abiut

unread,
Sep 19, 2016, 7:42:29 PM9/19/16
to 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

unread,
Sep 20, 2016, 3:11:42 AM9/20/16
to 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

unread,
Sep 20, 2016, 6:23:20 AM9/20/16
to 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

unread,
Sep 20, 2016, 8:42:56 PM9/20/16
to 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

unread,
Sep 21, 2016, 3:45:14 AM9/21/16
to 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
Reply all
Reply to author
Forward
0 new messages