terra_frugum
2010-08-25 18:26:03 UTC
Maybe this is trivial, but I simply cannot find an elegant solution.
I want to build a 'date' object programatically, that is, by specifying the
day, month and year numbers.
This can be accomplished by:
int d = 25;
int m = 8;
int y = 2010;
date myDate = str2date(strfmt("%1/%2/%3", d, m, y), 123);
My problem is that I want to find out the cases when d/m/y resolve to an
invalid date, such as 30/2/2010.
Unfortunately, str2date converts automatically the string "30/2/2010" to
Feb. 28, 2010!
I don't need the system to change the date to something valid; I simply want
it to tell me whether my input can create a valid date or not.
I even tried to use System.DateTime from .NET like this
try {
sysDt = new System.DateTime(2010, 2, 29);
myDate = sysDt;
print strfmt("%1", myDate);
} catch {
print "invalid";
}
which is almost what I want, but in addition I am saddled with an infolog
error message "Object 'CLRObject' could not be created".
Thanks!
I want to build a 'date' object programatically, that is, by specifying the
day, month and year numbers.
This can be accomplished by:
int d = 25;
int m = 8;
int y = 2010;
date myDate = str2date(strfmt("%1/%2/%3", d, m, y), 123);
My problem is that I want to find out the cases when d/m/y resolve to an
invalid date, such as 30/2/2010.
Unfortunately, str2date converts automatically the string "30/2/2010" to
Feb. 28, 2010!
I don't need the system to change the date to something valid; I simply want
it to tell me whether my input can create a valid date or not.
I even tried to use System.DateTime from .NET like this
try {
sysDt = new System.DateTime(2010, 2, 29);
myDate = sysDt;
print strfmt("%1", myDate);
} catch {
print "invalid";
}
which is almost what I want, but in addition I am saddled with an infolog
error message "Object 'CLRObject' could not be created".
Thanks!