osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

jilian to Gregorian date conversion error


ok so i have fixed that using the for loop

result_proxy=connection.execute(stmt).fetchall()
            for a in result_proxy:
                test=datetime.date.fromordinal(int(a.date_applied))


Now if i want to pass a range of date to date_applied above. How to i do that?

I know in sql i did did it like this
rate.columns.date_applied.between(covert,convert1)

where convert and convert1 are the range of date


cheers,



On Thu, Apr 26, 2018 at 4:47 AM, Dennis Lee Bieber <wlfraed at ix.netcom.com>
wrote:

> On Wed, 25 Apr 2018 13:43:15 +1100, sum abiut <suabiut at gmail.com>
> declaimed
> the following:
>
> >Thanks date example is 736788 in julian
> >
>
>         Okay...
> https://en.wikipedia.org/wiki/Julian_day#Julian_or_
> Gregorian_calendar_from_Julian_day_number
>
>         Using a calculator program based upon Duffett that converts to
>
> -2695.03205
>
> or
>         midnight, Mar 20, 2696BC
> (there is no year 0, so BC dates convert with a 1 year delta... 1BC is
> 0.xxx)
>
>         Note that       datetime.date.fromordinal()     is counting from
> Jan 1, 1AD; it
> is NOT Julian Day which counts from noon Jan 1, 4713BC
>
>         Treating your number as an ordinal gives
>
> >>> import datetime
> >>> datetime.date.fromordinal(736788)
> datetime.date(2018, 4, 4)
> >>>
>
> ... So your original problem is not with the number, per se, but perhaps in
> the format it has in
>
>                 rate.columns.date_applied
>
> is there a possibility that is a string field and not numeric?
>
> >>> st = "736788"
> >>> datetime.date.fromordinal(st)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
> TypeError: an integer is required
> >>> datetime.date.fromordinal(736788.0)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
> TypeError: integer argument expected, got float
> >>> import decimal
> >>> dc = decimal.Decimal(st)
> >>> dc
> Decimal('736788')
> >>> datetime.date.fromordinal(dc)
> datetime.date(2018, 4, 4)
> >>>
>
>
> --
>         Wulfraed                 Dennis Lee Bieber         AF6VN
>         wlfraed at ix.netcom.com    HTTP://wlfraed.home.netcom.com/
> --
> https://mail.python.org/mailman/listinfo/python-list
>