• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

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

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