473,748 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13043
On Dec 7, 7:20 am, Dirk Hagemann <DirkHagem...@g mail.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.x ldate_as_tuple( 38980,0)
(2006, 9, 20, 0, 0, 0)
>>>
chad!
Dec 7 '07 #2
On 7 Dez., 14:34, supercooper <supercoo...@gm ail.comwrote:
On Dec 7, 7:20 am, Dirk Hagemann <DirkHagem...@g mail.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.xl date_as_tuple(3 8980,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.xld ate_as_tuple(35 66985,0)
File "C:\Python25\li b\site-packages\xlrd\x ldate.py", line 75, in
xldate_as_tuple
raise XLDateTooLarge( xldate)
xlrd.xldate.XLD ateTooLarge: 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...@g mail.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...@g mail.comwrote:
On 7 Dez., 14:34, supercooper <supercoo...@gm ail.comwrote:
On Dec 7, 7:20 am, Dirk Hagemann <DirkHagem...@g mail.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.x ldate_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.xld ate_as_tuple(35 66985,0)
File "C:\Python25\li b\site-packages\xlrd\x ldate.py", line 75, in
xldate_as_tuple
raise XLDateTooLarge( xldate)
xlrd.xldate.XLD ateTooLarge: 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...@g mail.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=date time.datetime(1 901, 1, 1)
timezero+date time.timedelta( hours= 3566839)
datetime.dateti me(2307, 11, 27, 7, 0)
"""

Giles
Dec 7 '07 #6
me********@aol. com wrote:
On Dec 7, 7:20�am, Dirk Hagemann <DirkHagem...@g mail.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.timede lta (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.timede lta (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...@g mail.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.timede lta (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.timede lta (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...@g mail.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...@g mail.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.timede lta (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.timede lta (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...@g mail.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...@g mail.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.timede lta (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.timede lta (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

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

Similar topics

21
4242
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
43610
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
2645
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 I entered text values and for numeric columns I entered numeric values. It works fine and pass through all the validation checks and gets inserted into the database successfully. But when I gave some junk values in the excel sheet and tried to...
1
2154
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 is turned off). How would I go about converting some of this created code (example JS below), or is there an easier way to get PHP to do the calculations itself? I am aware of an excel-server product but this is too expensive and doesnt actually...
5
10328
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 create small programs. I was asked to write a small application that would look in a folder, and convert all the CSV files to XLS.
1
11371
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 to .MDB file. which I have already created with Table as Terms which contains 10 Fields and my Excel contains 10 Fields, Here I want to Extract 3 columns data from Excel to Table. Also it shows error of "syntax error in INSERT INTO Command. ...
1
8189
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 filtered code to a new column in a new Worksheet in a new Workbook. First, the VBA code: Set rData = wsData.Range("BQ5", wsData.Range("BQ65536").End(xlUp)) Set rTargetCl = wsTarget.Range("B65536").End(xlUp).Offset(1,0) With rData .AutoFilter...
11
4545
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 why it can't run? is it cos i should not be open my file in the win32::OLE module?
1
1712
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 ending up blank (Null, actually) contain: lu24769884l lu24769884xxl
1
3670
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
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.