Page 1 of 1

Getting a year from a given date

Posted: August 21st, 2019, 2:56 am
by munirmdee1
Hi all,

I have and application which has a variable which capture Date of Birth (named DOB), now I want to retrieve a year from that given date.
I know if I write this sysdate("YYYY"), I will get a year from it, but that will be current date, today date, I need to get a year from a specific given date.
How do I do in logic?

Thanks in Advance.

Re: Getting a year from a given date

Posted: August 21st, 2019, 7:26 am
by josh
Use the dateadd function.

dateadd(MYDATE, -1, "Y")

https://www.csprousers.org/help/CSPro/d ... ction.html

Re: Getting a year from a given date

Posted: August 22nd, 2019, 7:13 am
by munirmdee1
Thanks Josh,

But actually thats not what I meant. Maybe I did not use proper words, this is what I meant;

1. Assume in varioble DOB (Date of Birth) someone enters 20130623, whick means 2013, June 23.
2. Now I want to pick that year, which means 2013 from the varible DOB and put it in another variable called YearBirth.
3. Summary
DOB = 20130623
YearBirth = 2013

How do I accomplish that in logic? The variable YearBirth should get its value from DOB which is year 2013?

Thanks in Advance

Re: Getting a year from a given date

Posted: August 22nd, 2019, 7:18 am
by josh
Just divide by 10,000 to shift the year to the right by four places and then truncate:

YearBirth = int(DOB/10000)

int(20130623/10000) = int(2013.0632) = 2013