How to pass a date to from excel to C++?

  • Thread starter Thread starter Eric.Z
  • Start date Start date
Joined
12/13/11
Messages
83
Points
18
here is the VBA code:
function age(birth as date)
age = (today() - birth)/365.25
end function

However, if I want to use c++ dll. How to pass the variable birth to c++ as a date? And how to calculate the age?
 
here is the VBA code:
function age(birth as date)
age = (today() - birth)/365.25
end function

However, if I want to use c++ dll. How to pass the variable birth to c++ as a date? And how to calculate the age?

Hey crazymath, I do not think there is a simple way to do that. May be someone here would be able to give you a better advice, but here is the way to think about it. Convert your date type to double type which you can directly send to C++ dll. In vba code do something like 10000*year + 100*month + day. You will get a numeric value that way you can pass an argument to C++ dll like double to double.

Then in C++ work with <ctime.h> library using tm structure and difftime method.

Good Luck
 
Hey crazymath, I do not think there is a simple way to do that. May be someone here would be able to give you a better advice, but here is the way to think about it. Convert your date type to double type which you can directly send to C++ dll. In vba code do something like 1000*year + 10*month + day. You will get a numeric value that way you can pass an argument to C++ dll like double to double.

Then in C++ work with <ctime.h> library using tm structure and difftime method.

Good Luck
thanks. This is exactly what I am looking for.
 
Back
Top Bottom