04-16-2007 12:45 PM
04-17-2007 01:25 AM
Hi Kurt,
Could you send the value that you read from Excel as double?
It may look meaningless but the date and time values may be kept as a single number giving, for example, the number of seconds since some reference time in the past.
CVI has some time format conversion functions some of which are in the ANSI library. That value you got from Excel might be meaningful for one of them.
Just "surf" a little in the function libraries.
If you post the value I can help more.
04-17-2007 05:19 AM
Hello Eblaci
Thanks for your reply, I've tried a bit further without result, so I've attached my project. Make your project path C:\Source\PdYieldToDb and it should work. The excel file is Test.xls The call to the cell is from the main function.
Thanks again for your help!
best regards
Kurt
04-17-2007 05:45 AM
Hi Kurt,
I just need the double value, I mean a single number. Not the whole project.
I cannot run your project because I do not have CVI installed in this machine.
You can simply debug your code and copy the number you got from Excel into the post.
04-17-2007 05:57 AM
Hello Ebalci,
the double value returned is 39184. The value in the date cell is 12.04.2007.
best regards
Kurt
04-17-2007 08:05 AM
I think that is the number of days since 1st Jan 1900.
JR
04-17-2007 08:22 AM - edited 04-17-2007 08:22 AM
Hi Kurt,
A little search in CVI, Excel help and Google gives the following results:
The link has the source code in it. But it would give compiler errors in CVI when copied directly. I tried to "clean" the code in a text editor (since I do not have CVI right now) and I hope it will compile. I paste the code below.
You paste it in a file and just call it with necessary parameters.
Please let me know if something goes wrong so I can edit the post.
Note: You may also check that link to verify the relation between Excel and Gregorian calendar formats http://www.calendarhome.com/converter/
void ExcelSerialDateToDMY(int nSerialDate, int *nDay, int *nMonth, int *nYear)
{
int l, n, i, j;
// Excel/Lotus 123 have a bug with 29-02-1900. 1900 is not a
// leap year, but Excel/Lotus 123 think it is...
if (nSerialDate == 60)
{
(*nDay) = 29;
(*nMonth) = 2;
(*nYear) = 1900;
return;
}
else if (nSerialDate < 60)
{
// Because of the 29-02-1900 bug, any serial date
// under 60 is one off... Compensate.
nSerialDate++;
}
// Modified Julian to DMY calculation with an addition of 2415019
l = nSerialDate + 68569 + 2415019;
n = (int)(( 4 * l ) / 146097);
l = l - (int)(( 146097 * n + 3 ) / 4);
i = (int)(( 4000 * ( l + 1 ) ) / 1461001);
l = l - (int)(( 1461 * i ) / 4) + 31;
j = (int)(( 80 * l ) / 2447);
(*nDay) = l - (int)(( 2447 * j ) / 80);
l = (int)(j / 11);
(*nMonth) = j + 2 - ( 12 * l );
(*nYear) = 100 * ( n - 49 ) + i + l;
}
Message Edited by ebalci on 04-17-2007 04:28 PM
04-17-2007 08:57 AM
All right Ebalci!
that did the trick! It gave back the correct date.
Thank you very much!
best regards
Kurt
04-17-2007 02:13 PM
You are welcome, Kurt.
I am also glad that it worked