Hi Quish,
Internally, Excel does not have a DateTime data type. What you see in
the sheet is just a special number format applied to a double value.
(There are also no other numeric types, like int, in Excel.)
So I doubt you'll find a perfect solution. Something like
=myFunction("5 January 2010" + 1) might be really hard to deal with.
Other than retrieving and parsing the whole formula yourself, I know
of no way to distinguish this from =myFunction(40180).
Excel has some special handling for certain internal functions like
=NOW(), but generally this aspect is problematic.
Your approach might differ for values typed into the parameters, and
for a reference to another cell containing the date value. By marking
your ExcelArgument as AllowReference=true you will get the actual
reference to the cell as an ExcelReference type and not just the
value, and can sometimes act accordingly.
Maybe:
1. For a reference you could convert the cell contents to a string
using xlCoerce, and then parse the string.
2. For a reference you could try to read the numeric format string
using option 7 of xlcGetCell (your function must then be marked with
IsMacroType=true). Then you have to parse the number format and figure
out whether it is a date/time format. This sounds painful to me.
3. For a value you could try to see whether the DateTime you get from
your check is in a reasonable range for the dates you expect, but of
course this is not great if you also have numbers that could be in
that range.
I would suggest you re-think your function interface so that you don't
have to deal with this problem at all. It might be better to
automatically generate a family of functions than to have such a
generic one where you have to figure out the parameter types based
purely on what is passed in...?
-Govert