calculate difference in date variables

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
kamal
Posts: 5
Joined: February 2nd, 2019, 1:08 pm

calculate difference in date variables

Post 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....
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: calculate difference in date variables

Post 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.
kamal
Posts: 5
Joined: February 2nd, 2019, 1:08 pm

Re: calculate difference in date variables

Post 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;
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: calculate difference in date variables

Post 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.
Post Reply