Page 1 of 1

calculate difference in date variables

Posted: February 2nd, 2019, 1:43 pm
by kamal
if q201 as date variable defined with subitems as q201_yy(4), q201_mm(2),q201_dd(2)

one more date variable is defined as q501 with subitems as q501_yy(4), q501_mm(2), q501_dd(2).

anyway to calculate the difference in dates say date in q501 and q201 cannot be <10 days .....even if the date is added/ or again updated then the logic provided should work....

Re: calculate difference in date variables

Posted: February 2nd, 2019, 9:33 pm
by khurshid.arshad
Dear kamal

Please check DateDiff Function in help.

if your date is stored as string then

Code: Select all

string firstdateconcate=concat (Q201_YY_4, Q201_MM_2, Q201_DD_2);
string seconddateconcate=concat (Q501_YY_4, Q501_MM_2, Q501_DD_2);
	if datediff(tonumber(firstdateconcate),(tonumber(seconddateconcate)),"dd")<10 then
		errmsg ("Date difference can not be less than 10 days." );
	reenter;
	else
	endif;
if date is stored as numeric then

Code: Select all


string firstdateconcate=concat (edit ("9999",Q201_YY_4), edit ("99",Q201_MM_2), edit("99",Q201_DD_2));
string seconddateconcate=concat (edit("9999",Q501_YY_4), edit ("99",Q501_MM_2), edit("99",Q501_DD_2));

	if datediff(tonumber(firstdateconcate),tonumber(seconddateconcate),"dd")<10 then
		errmsg ("Date difference can not be less than 10 days." );
		reenter;
	else
	endif;
	
[code]
Best.
a.

Re: calculate difference in date variables

Posted: February 3rd, 2019, 5:17 am
by kamal
Thx.. .but still not working...
W201 is alpha variable as date (yyyymmdd) with subitems w201yy w201mm w201dd as numerics...
Similarly for W501A1 as date (yyyymmdd) with subitems numeric as w501a1_yy, w501a1_mm, w501a1_dd as numerics...
wherein for both the above variables subitems year is 4 digits numiercs, month is 2 digits numeric and date is 2 digit numerics.
string firstdateconcate=concat (edit ("9999",W201YY), edit ("99",W201MM), edit("99",W201DD));
string seconddateconcate=concat (edit("9999",W501A1_YY), edit ("99",W501A1_MM), edit("99",W501A1_DD));

if datediff(tonumber(firstdateconcate),tonumber(seconddateconcate),"dd")>10 then
errmsg ("Date difference can not be less than 10 days." );
reenter;
else
endif;

Re: calculate difference in date variables

Posted: February 4th, 2019, 8:05 am
by Gregory Martin
Take a look at the datediff help page:

http://www.csprousers.org/help/CSPro/da ... ction.html

There is no "dd" formatter. Try changing that to "d" and if that doesn't work, perhaps you can post your application and someone can look at it.