Date(YYYYMMDD) or Date(DDMMYYYY)

Discussions about CSEntry
Post Reply
sham
Posts: 69
Joined: February 3rd, 2022, 7:30 pm

Date(YYYYMMDD) or Date(DDMMYYYY)

Post by sham »

Hi family,
Thank you so much for your guide...
I have successfully created a variable name(Item) called DOI with sub items to automatically capture the system date with logic as stated below

PROC DOI
preproc
if demode() = 1 then
DOI = sysdate("DDMMYYYY");
endif;

Now

I have successfully created a variable name(Item) called DOB with sub items for enumerators to capture the Date of Birth in same format as
(DDMMYYY) with a logic to validate the date of birth as indicated below;

PROC DOB
numeric birthDate = A1C * 10000 + A1B * 100 + A1A;
numeric isValidDate = datevalid(birthDate);
if not isValidDate then
errmsg("Birth date - %d/%d-%d is not a valid date. Please reenter", A1A, A1B, A1C);
endif;

Now I have have created a 3rd variable(Item) called Age in complete(D1) for the enumerators to enter the complete Age of the respondent refrence the the Date caputured above.
I taught of creating a logic to actually validate the ages the enumerators captured in (D1) using the Datediff function as below;

PROC D1
postproc
if datediff(DOB, DOI, "y") <> D1 then
errmsg("Age (%d) does not match date of birth (%d)", D1, DOB)
select("Correct Age", D1, "Correct date of birth", DOI);
endif;
And it is not working.

I need clarity on how to go around this without changing the paten of the date format ( from DDMMYYYY) to (YYYYMMDD)

I attached the file for your study.

Thank you.
Sham.
Attachments
DATE ISUES.zip
(46.21 KiB) Downloaded 78 times
Gregory Martin
Posts: 1792
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Date(YYYYMMDD) or Date(DDMMYYYY)

Post by Gregory Martin »

You'll have to convert the dates to use the CSPro built-in functions. See here for an example:

viewtopic.php?f=1&t=3458
sham
Posts: 69
Joined: February 3rd, 2022, 7:30 pm

Re: Date(YYYYMMDD) or Date(DDMMYYYY)

Post by sham »

@ George,
Thank you soo much.
AM very grateful
Post Reply