473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Converting Excel time-format (hours since 1.1.1901)

Hello,

From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).

You might guess what I need now: I want to calculate this somehow in
python.

Sorry, but I couldn't find anything in the module time or something
else to get this calculated.

Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?

Thanks a lot and regards
Dirk
Dec 7 '07 #1
18 13002
On Dec 7, 7:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,

From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).

You might guess what I need now: I want to calculate this somehow in
python.

Sorry, but I couldn't find anything in the module time or something
else to get this calculated.

Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?

Thanks a lot and regards
Dirk
I think you want the xldate_as_tuple function in the xlrd module:

http://www.lexicon.net/sjmachin/xlrd.htm

It works like a champ for me:
>>import xlrd
xlrd.xldate.xldate_as_tuple(38980,0)
(2006, 9, 20, 0, 0, 0)
>>>
chad!
Dec 7 '07 #2
On 7 Dez., 14:34, supercooper <supercoo...@gmail.comwrote:
On Dec 7, 7:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).
You might guess what I need now: I want to calculate this somehow in
python.
Sorry, but I couldn't find anything in the module time or something
else to get this calculated.
Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?
Thanks a lot and regards
Dirk

I think you want the xldate_as_tuple function in the xlrd module:

http://www.lexicon.net/sjmachin/xlrd.htm

It works like a champ for me:
>import xlrd
xlrd.xldate.xldate_as_tuple(38980,0)

(2006, 9, 20, 0, 0, 0)

chad!
Thanks so far, that comes close to a solution I think, BUT when I
enter 3566985 instead of 38980 I get the following error:
Traceback (most recent call last):
File "test.py", line 20, in <module>
print xlrd.xldate.xldate_as_tuple(3566985,0)
File "C:\Python25\lib\site-packages\xlrd\xldate.py", line 75, in
xldate_as_tuple
raise XLDateTooLarge(xldate)
xlrd.xldate.XLDateTooLarge: 3566985

Do I have to use another function of this module? My number is 2
digits shorter than yours. What is 38980 representing?

Dirk
Dec 7 '07 #3
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,

From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
Your guess appears to be off by a couple centuries.

(3566839/24)/365 = 407
For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) �(put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).

You might guess what I need now: I want to calculate this somehow in
python.

Sorry, but I couldn't find anything in the module time or something
else to get this calculated.

Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?

Thanks a lot and regards
Dirk
Dec 7 '07 #4
On Dec 7, 8:15 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 14:34, supercooper <supercoo...@gmail.comwrote:
On Dec 7, 7:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).
You might guess what I need now: I want to calculate this somehow in
python.
Sorry, but I couldn't find anything in the module time or something
else to get this calculated.
Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?
Thanks a lot and regards
Dirk
I think you want the xldate_as_tuple function in the xlrd module:
http://www.lexicon.net/sjmachin/xlrd.htm
It works like a champ for me:
>>import xlrd
>>xlrd.xldate.xldate_as_tuple(38980,0)
(2006, 9, 20, 0, 0, 0)
chad!

Thanks so far, that comes close to a solution I think, BUT when I
enter 3566985 instead of 38980 I get the following error:
Traceback (most recent call last):
File "test.py", line 20, in <module>
print xlrd.xldate.xldate_as_tuple(3566985,0)
File "C:\Python25\lib\site-packages\xlrd\xldate.py", line 75, in
xldate_as_tuple
raise XLDateTooLarge(xldate)
xlrd.xldate.XLDateTooLarge: 3566985

Do I have to use another function of this module? My number is 2
digits shorter than yours. What is 38980 representing?

Dirk
Excel stores dates as floating point
numbers; the number of days (or fraction thereof) since
12/31/1899. So 38980.0 is midnight 9/20/2006. You think your numbers
represent
the number of hours since 1/1/1901?

3,566,985 hrs/24 hrs in a day = ~148,618 days
148,618 days/365 days in a year = ~407 years

Am I doing the math wrong?
Dec 7 '07 #5
On 7 Dec, 13:20, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,

From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
For Example: the number 3566839 is 27.11.07 7:00. To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).

You might guess what I need now: I want to calculate this somehow in
python.

Sorry, but I couldn't find anything in the module time or something
else to get this calculated.

Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?

Thanks a lot and regards
Dirk
Something is a bit off here...

"""
>>import datetime
timezero=datetime.datetime(1901, 1, 1)
timezero+datetime.timedelta(hours= 3566839)
datetime.datetime(2307, 11, 27, 7, 0)
"""

Giles
Dec 7 '07 #6
me********@aol.com wrote:
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
>Hello,

From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
If it *is* then the easiest way is this:

<code>
import datetime
print datetime.date (1901, 1, 1) + datetime.timedelta (hours=3566839)

</code>

But, as someone pointed out, that puts you somewhere in 2300.
Where are you getting the 1901 from (and the hours, for that
matter). If it's based, as AD dates are, for example, from 1601,
then the calc becomes:

<code>
import datetime
print datetime.date (1601, 1, 1) + datetime.timedelta (hours=3566839)

</code>

which looks more realistic. But frankly I'm guessing.

TJG
Dec 7 '07 #7
On 7 Dez., 16:21, Tim Golden <m...@timgolden.me.ukwrote:
mensana...@aol.com wrote:
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.

If it *is* then the easiest way is this:

<code>
import datetime
print datetime.date (1901, 1, 1) + datetime.timedelta (hours=3566839)

</code>

But, as someone pointed out, that puts you somewhere in 2300.
Where are you getting the 1901 from (and the hours, for that
matter). If it's based, as AD dates are, for example, from 1601,
then the calc becomes:

<code>
import datetime
print datetime.date (1601, 1, 1) + datetime.timedelta (hours=3566839)

</code>

which looks more realistic. But frankly I'm guessing.

TJG
(3566839/24)/365 = 407 - YES I did this calculation too and was
surprised. But if you try this out in MS Excel:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-fieldby right-
click on it to the
date format "14.3.01 13:30")

and then replace 3566839 by, let's say, "2", Excel calculates the date
01.10.1901 2:00 AM. Try out other values like 5 or 24! So I thought
3566839 represents hours.

Dirk
Dec 7 '07 #8
On 7 Dez., 16:50, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 16:21, Tim Golden <m...@timgolden.me.ukwrote:
mensana...@aol.com wrote:
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
>Hello,
>From a zone-file of a Microsoft Active Directory integrated DNS server
>I get the date/time of the dynamic update entries in a format, which
>is as far as I know the hours since january 1st 1901.
If it *is* then the easiest way is this:
<code>
import datetime
print datetime.date (1901, 1, 1) + datetime.timedelta (hours=3566839)
</code>
But, as someone pointed out, that puts you somewhere in 2300.
Where are you getting the 1901 from (and the hours, for that
matter). If it's based, as AD dates are, for example, from 1601,
then the calc becomes:
<code>
import datetime
print datetime.date (1601, 1, 1) + datetime.timedelta (hours=3566839)
</code>
which looks more realistic. But frankly I'm guessing.
TJG

(3566839/24)/365 = 407 - YES I did this calculation too and was
surprised. But if you try this out in MS Excel:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-fieldby right-
click on it to the
date format "14.3.01 13:30")

and then replace 3566839 by, let's say, "2", Excel calculates the date
01.10.1901 2:00 AM. Try out other values like 5 or 24! So I thought
3566839 represents hours.

Dirk
Additional to my last posting: if you want to try this out in Excel
you should replace the command "REST" by the english command what
should be something like "remainder".
Dec 7 '07 #9
On 7 Dez., 16:50, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 16:21, Tim Golden <m...@timgolden.me.ukwrote:
mensana...@aol.com wrote:
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
>Hello,
>From a zone-file of a Microsoft Active Directory integrated DNS server
>I get the date/time of the dynamic update entries in a format, which
>is as far as I know the hours since january 1st 1901.
If it *is* then the easiest way is this:
<code>
import datetime
print datetime.date (1901, 1, 1) + datetime.timedelta (hours=3566839)
</code>
But, as someone pointed out, that puts you somewhere in 2300.
Where are you getting the 1901 from (and the hours, for that
matter). If it's based, as AD dates are, for example, from 1601,
then the calc becomes:
<code>
import datetime
print datetime.date (1601, 1, 1) + datetime.timedelta (hours=3566839)
</code>
which looks more realistic. But frankly I'm guessing.
TJG

(3566839/24)/365 = 407 - YES I did this calculation too and was
surprised. But if you try this out in MS Excel:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-fieldby right-
click on it to the
date format "14.3.01 13:30")

and then replace 3566839 by, let's say, "2", Excel calculates the date
01.10.1901 2:00 AM. Try out other values like 5 or 24! So I thought
3566839 represents hours.

Dirk
Oh - sorry again: in the Excel formula replace also ZEIT with TIME.
Dec 7 '07 #10
If we use minutes from 2001, then 3566839 comes out as sometime in
October, 2007 (6.78622 years). Close but no cigar. Is anyone familar
enough with Excel to translate the formula or do we have to go a-
googling?
Dec 7 '07 #11
Dirk Hagemann <Di**********@gmail.comwrote:
>Dirk
Additional to my last posting: if you want to try this out in
Excel you should replace the command "REST" by the english
command what should be something like "remainder".
The equivalent in my (U.S. English, 2000) version of excel is called
'MOD'.

Also, you have misread or miscopied something, or are encountering
some very strange issue, as when I put your formula in excel, I get
the following output:

11/27/2307 7:00
max
Dec 7 '07 #12
Dirk Hagemann wrote:
(3566839/24)/365 = 407 - YES I did this calculation too and was
surprised. But if you try this out in MS Excel:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-fieldby right-
click on it to the
date format "14.3.01 13:30")

and then replace 3566839 by, let's say, "2", Excel calculates the date
01.10.1901 2:00 AM.
Hum, how can it be that Excel changes from YY to YYYY year display format ? What
does it display in the first case with a YYYY display format ?
Dec 7 '07 #13
On Dec 7, 9:59*am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 16:50, Dirk Hagemann <DirkHagem...@gmail.comwrote:


On 7 Dez., 16:21, Tim Golden <m...@timgolden.me.ukwrote:
mensana...@aol.com wrote:
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
If it *is* then the easiest way is this:
<code>
import datetime
print datetime.date (1901, 1, 1) + datetime.timedelta (hours=3566839)
</code>
But, as someone pointed out, that puts you somewhere in 2300.
Where are you getting the 1901 from (and the hours, for that
matter). If it's based, as AD dates are, for example, from 1601,
then the calc becomes:
<code>
import datetime
print datetime.date (1601, 1, 1) + datetime.timedelta (hours=3566839)
</code>
which looks more realistic. But frankly I'm guessing.
TJG
(3566839/24)/365 = 407 * - YES I did this calculation too and was
surprised. But if you try this out in MS Excel:
*="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) *(put
3566839 in field A1 and switch the format of the result-fieldby right-
click on it to the
date format "14.3.01 13:30")
and then replace 3566839 by, let's say, "2", Excel calculates the date
01.10.1901 2:00 AM. Try out other values like 5 or 24! So I thought
3566839 represents hours.
Dirk

Oh - sorry again: in the Excel formula replace also ZEIT with TIME
Also, Excel unformatted dates are DAYS, not hours. And it's
from 1900, not 1901. Hours are always fractional parts:

1/1/01 0:00 367
1/1/01 12:00 367.5

It sure sounds like the number being given you ISN'T the
same as Excel date serial numbers.
Dec 7 '07 #14
On Dec 8, 12:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,

From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
As Tim Golden has guessed, it is the number of hours since
1601-01-01T00:00:00. Weird but true. See (for example)
http://www.netpro.com/forum/messagev...5&threadid=457
For Example: the number 3566839 is 27.11.07 7:00.
Y2K bug! The number 3566839 is a representation of
2007-11-27T07:00:00.
To calculate this in
Excel I use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).
"01.01.1901" =date(1901, 1, 1)

(A1/24-(REST(A1;24)/24)) =(A1/24-(MOD(A1,24)/24))
which simplifies to INT(A1/24)

ZEIT(REST(A1;24);0;0) =TIME(MOD(A1,24),0,0)

This is a convoluted way of writing DATE(1901, 1, 1) + A1 / 24

Your result is "correct" apart from the century. This is the result of
two canceling errors (1) yours in being 3 centuries out of kilter (2)
Microsoft's in perpetuating the Lotus 123 "1900 is a leap year" bug.

If you must calculate this in Excel, this formula might be better:

=DATE(2001, 1, 1) + A1 / 24 - 146097

(146097 is the number of days in a 400-year cycle, 400 * 365 + 100 - 4
+ 1)
>
You might guess what I need now: I want to calculate this somehow in
python.

Sorry, but I couldn't find anything in the module time or something
else to get this calculated.

Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?
One very slight change to what Tim Golden suggested: make the result a
datetime, not a date.
>>dnsdatetime2py = lambda x: datetime.datetime(1601,1,1,0,0,0) + datetime.timedelta(hours=x)
dnsdatetime2py(3566839) # your example
datetime.datetime(2007, 11, 27, 7, 0)
>>dnsdatetime2py(3554631) # example in cited web posting
datetime.datetime(2006, 7, 6, 15, 0)

HTH,
John
Dec 7 '07 #15
On 7 Dez., 22:36, John Machin <sjmac...@lexicon.netwrote:
On Dec 8, 12:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.

As Tim Golden has guessed, it is the number of hours since
1601-01-01T00:00:00. Weird but true. See (for example)http://www.netpro.com/forum/messagev...5&threadid=457
For Example: the number 3566839 is 27.11.07 7:00.

Y2K bug! The number 3566839 is a representation of
2007-11-27T07:00:00.
To calculate this in
ExcelI use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) (put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).

"01.01.1901" =date(1901, 1, 1)

(A1/24-(REST(A1;24)/24)) =(A1/24-(MOD(A1,24)/24))
which simplifies to INT(A1/24)

ZEIT(REST(A1;24);0;0) =TIME(MOD(A1,24),0,0)

This is a convoluted way of writing DATE(1901, 1, 1) + A1 / 24

Your result is "correct" apart from the century. This is the result of
two canceling errors (1) yours in being 3 centuries out of kilter (2)
Microsoft's in perpetuating the Lotus 123 "1900 is a leap year" bug.

If you must calculate this inExcel, this formula might be better:

=DATE(2001, 1, 1) + A1 / 24 - 146097

(146097 is the number of days in a 400-year cycle, 400 * 365 + 100 - 4
+ 1)
You might guess what I need now: I want to calculate this somehow in
python.
Sorry, but I couldn't find anything in the module time or something
else to get this calculated.
Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?

One very slight change to what Tim Golden suggested: make the result a
datetime, not a date.
>dnsdatetime2py = lambda x: datetime.datetime(1601,1,1,0,0,0) + datetime.timedelta(hours=x)
dnsdatetime2py(3566839) # your example

datetime.datetime(2007, 11, 27, 7, 0)>>dnsdatetime2py(3554631) # example in cited web posting

datetime.datetime(2006, 7, 6, 15, 0)

HTH,
John
YES - that's it!
Thanks a lot to John, Tim and all the others who helped me to handle
this time format!!!

I was irritated by the date of 01.01.1901 in the Excel formula, but in
the end it was obvious that it has to be hours since 1601. Who knows
how Excel calculates in the background...

Enjoy the sunday and have a great week!
Dirk
Dec 9 '07 #16
On Dec 9, 8:52�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 22:36, John Machin <sjmac...@lexicon.netwrote:


On Dec 8, 12:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
As Tim Golden has guessed, it is the number of hours since
1601-01-01T00:00:00. Weird but true. See (for example)http://www.netpro.com/forum/messagev...5&threadid=457
For Example: the number 3566839 is 27.11.07 7:00.
Y2K bug! The number 3566839 is a representation of
2007-11-27T07:00:00.
To calculate this in
>ExcelI use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) �(put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).
"01.01.1901" =date(1901, 1, 1)
(A1/24-(REST(A1;24)/24)) =(A1/24-(MOD(A1,24)/24))
which simplifies to INT(A1/24)
ZEIT(REST(A1;24);0;0) =TIME(MOD(A1,24),0,0)
This is a convoluted way of writing DATE(1901, 1, 1) + A1 / 24
Your result is "correct" apart from the century. This is the result of
two canceling errors (1) yours in being 3 centuries out of kilter (2)
Microsoft's in perpetuating the Lotus 123 "1900 is a leap year" bug.
If you must calculate this inExcel, this formula might be better:
=DATE(2001, 1, �1) + A1 / 24 - 146097
(146097 is the number of days in a 400-year cycle, 400 * 365 + 100 - 4
+ 1)
You might guess what I need now: I want to calculate this somehow in
python.
Sorry, but I couldn't find anything in the module time or something
else to get this calculated.
Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?
One very slight change to what Tim Golden suggested: make the result a
datetime, not a date.
>>dnsdatetime2py = lambda x: datetime.datetime(1601,1,1,0,0,0) + datetime.timedelta(hours=x)
>>dnsdatetime2py(3566839) # your example
datetime.datetime(2007, 11, 27, 7, 0)>>dnsdatetime2py(3554631) # example in cited web posting
datetime.datetime(2006, 7, 6, 15, 0)
HTH,
John

YES - that's it!
Thanks a lot to John, Tim and all the others who helped me to handle
this time format!!!

I was irritated by the date of 01.01.1901 in the Excel formula, but in
the end it was obvious that it has to be hours since 1601. Who knows
how Excel calculates in the background...
Everyone knows. Excel assumes an integer is
DAYS SINCE 1900 and all it's calculations
are based on that assumption.

It's YOUR fault if you give Excel an integer
that represents HOURS SINCE 1601, so don't
expect meaningful calculations from Excel if
you give it an incorrect data type.
>
Enjoy the sunday and have a great week!
Dirk
Dec 9 '07 #17
On 9 Dez., 18:38, "mensana...@aol.com" <mensana...@aol.comwrote:
On Dec 9, 8:52�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 22:36, John Machin <sjmac...@lexicon.netwrote:
On Dec 8, 12:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
As Tim Golden has guessed, it is the number of hours since
1601-01-01T00:00:00. Weird but true. See (for example)http://www.netpro.com/forum/messagev...5&threadid=457
For Example: the number 3566839 is 27.11.07 7:00.
Y2K bug! The number 3566839 is a representation of
2007-11-27T07:00:00.
To calculate this in
ExcelI use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) �(put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).
"01.01.1901" =date(1901, 1, 1)
(A1/24-(REST(A1;24)/24)) =(A1/24-(MOD(A1,24)/24))
which simplifies to INT(A1/24)
ZEIT(REST(A1;24);0;0) =TIME(MOD(A1,24),0,0)
This is a convoluted way of writing DATE(1901, 1, 1) + A1 / 24
Your result is "correct" apart from the century. This is the result of
two canceling errors (1) yours in being 3 centuries out of kilter (2)
Microsoft's in perpetuating the Lotus 123 "1900 is a leap year" bug.
If you must calculate this inExcel, this formula might be better:
=DATE(2001, 1, �1) + A1 / 24 - 146097
(146097 is the number of days in a 400-year cycle, 400 * 365 + 100 - 4
+ 1)
You might guess what I need now: I want to calculate this somehow in
python.
Sorry, but I couldn't find anything in the module time or something
else to get this calculated.
Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?
One very slight change to what Tim Golden suggested: make the result a
datetime, not a date.
>dnsdatetime2py = lambda x: datetime.datetime(1601,1,1,0,0,0) + datetime.timedelta(hours=x)
>dnsdatetime2py(3566839) # your example
datetime.datetime(2007, 11, 27, 7, 0)>>dnsdatetime2py(3554631) # example in cited web posting
datetime.datetime(2006, 7, 6, 15, 0)
HTH,
John
YES - that's it!
Thanks a lot to John, Tim and all the others who helped me to handle
this time format!!!
I was irritated by the date of 01.01.1901 in the Excel formula, but in
the end it was obvious that it has to be hours since 1601. Who knows
how Excel calculates in the background...

Everyone knows. Excel assumes an integer is
DAYS SINCE 1900 and all it's calculations
are based on that assumption.

It's YOUR fault if you give Excel an integer
that represents HOURS SINCE 1601, so don't
expect meaningful calculations from Excel if
you give it an incorrect data type.
Enjoy the sunday and have a great week!
Dirk
Sorry, but then I seem not to belong to "everyone". And it was not me
who created this Excel-formula, I just posted it as a kind of help.
And actually I just asked if somebody knows something about this time-
format and how to convert it. I think I already wrote that I did a
mistake and not Excel.
Dec 10 '07 #18
On Dec 10, 3:49*am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 9 Dez., 18:38, "mensana...@aol.com" <mensana...@aol.comwrote:


On Dec 9, 8:52�am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
On 7 Dez., 22:36, John Machin <sjmac...@lexicon.netwrote:
On Dec 8, 12:20 am, Dirk Hagemann <DirkHagem...@gmail.comwrote:
Hello,
From a zone-file of a Microsoft Active Directory integrated DNS server
I get the date/time of the dynamic update entries in a format, which
is as far as I know the hours since january 1st 1901.
As Tim Golden has guessed, it is the number of hours since
1601-01-01T00:00:00. Weird but true. See (for example)http://www.netpro.com/forum/messagev...5&threadid=457
For Example: the number 3566839 is 27.11.07 7:00.
Y2K bug! The number 3566839 is a representation of
2007-11-27T07:00:00.
To calculate this in
>ExcelI use this:
="01.01.1901"+(A1/24-(REST(A1;24)/24))+ZEIT(REST(A1;24);0;0) �(put
3566839 in field A1 and switch the format of the result-field to the
corresponding date-time format).
"01.01.1901" =date(1901, 1, 1)
(A1/24-(REST(A1;24)/24)) =(A1/24-(MOD(A1,24)/24))
which simplifies to INT(A1/24)
ZEIT(REST(A1;24);0;0) =TIME(MOD(A1,24),0,0)
This is a convoluted way of writing DATE(1901, 1, 1) + A1 / 24
Your result is "correct" apart from the century. This is the result of
two canceling errors (1) yours in being 3 centuries out of kilter (2)
Microsoft's in perpetuating the Lotus 123 "1900 is a leap year" bug.
If you must calculate this inExcel, this formula might be better:
=DATE(2001, 1, �1) + A1 / 24 - 146097
(146097 is the number of days in a 400-year cycle, 400 * 365 + 100 -4
+ 1)
You might guess what I need now: I want to calculate this somehow in
python.
Sorry, but I couldn't find anything in the module time or something
else to get this calculated.
Does anyone know how to convert this time in python to something
usable or how to convert this formula in python?
One very slight change to what Tim Golden suggested: make the resulta
datetime, not a date.
>>dnsdatetime2py = lambda x: datetime.datetime(1601,1,1,0,0,0) +datetime.timedelta(hours=x)
>>dnsdatetime2py(3566839) # your example
datetime.datetime(2007, 11, 27, 7, 0)>>dnsdatetime2py(3554631) # example in cited web posting
datetime.datetime(2006, 7, 6, 15, 0)
HTH,
John
YES - that's it!
Thanks a lot to John, Tim and all the others who helped me to handle
this time format!!!
I was irritated by the date of 01.01.1901 in the Excel formula, but in
the end it was obvious that it has to be hours since 1601. Who knows
how Excel calculates in the background...
Everyone knows. Excel assumes an integer is
DAYS SINCE 1900 and all it's calculations
are based on that assumption.
It's YOUR fault if you give Excel an integer
that represents HOURS SINCE 1601, so don't
expect meaningful calculations from Excel if
you give it an incorrect data type.
Enjoy the sunday and have a great week!
Dirk

Sorry, but then I seem not to belong to "everyone".
I apologize for the snide tone. But the reality is that
you DO belong to everyone as how Excel calculates time
in the background is explicitly stated in the Help files.
And it was not me
who created this Excel-formula, I just posted it as a kind of help.
And actually I just asked if somebody knows something about this time-
format and how to convert it. I think I already wrote that I did a
mistake and not Excel.
I wasn't trying to assign blame. There's a computer term
called GIGO, it stands for Garbage In, Garbage Out. It means
that even if your formulae are correct, the result will be
no better than the input, bad input produces bad output and
the computer has no way to tell this. It is the programmer's
responsibility to verify consistency. The magnitude of the
number is inconsitent with Excel time formats. That's a clue
that you can't use Excel date functions directly on this number.
It is also inconsistent with hours from 1901 as it would be
off by 4 centuries. That's a clue that either the formula
is wrong or your interpretation of it is wrong.

Once you have all the wrinkles ironed out, it will then
become clear how to convert this number to it's equivalent
Excel format so that you CAN use Excel date functions if
desired.

Dec 10 '07 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Davinder | last post by:
can anyone recommend a good tool to convert documents to HTML on the fly. I need to integrate this tool with a VB app so it must have an API. thanks in advance Davinder davinder@gujral.co.uk
20
by: Ollie | last post by:
Ok, As the Convert.ToDateTime has not been implimented yet, how do I convert a double to datetime??? I have looked all over with no luck at all. Please help me!
1
by: Ramakrishnan Nagarajan | last post by:
Hi, I am converting Excel data into a Dataset in C#. There are around 24 columns in the Excel Sheet. First I tried to insert one row with correct values in the Excel sheet. i.e. for text columns...
1
by: UKuser | last post by:
Hi Guys, I have a program which converts Excel spreadsheets to Javascript and allows interactivity. However it can't convert it to PHP, which is obviously better for users to view (in case J/S...
5
by: Testguy | last post by:
Hi, I was wondering if one the smart people that frequent this group could give me a hand with a small program I am attempting to debug. I am not a highly experienced developer, but can...
1
by: ShailShin | last post by:
Hi All, I have to convert Excel data to MSAcess .MDB file using VB.NET. VB.NET Code read the Excel file and write it to .MDB file. For the same I have below code, but I am stuck at the writing it...
1
by: doug9149 | last post by:
Hello all, I've got some code I wrote using VBA for Excel that I'm trying to recreate using C#.NET. The code autofilters 1 entire column from 1 Worksheet from a Workbook and then appends this...
11
by: poolboi | last post by:
hi guys, below is a script that i need yr help on i got this to print out a csv to excel i'm trying to modify it to read a .txt file to convert an excel hm...doesn't seem to work still any idea...
1
by: PW | last post by:
Hi, When I run the following command, some fields are ending up blank when the clearly have values them in Excel. I have tried converting the columns to general and text. The ones that are...
1
by: =?Utf-8?B?bGF3ODc4Nw==?= | last post by:
i am looking for some MS Excel formula or MS Visal Basic Marco for converting Date to Lunar Date. tks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.