Getting a year from a given date

Discussions about CSEntry
Post Reply
munirmdee1
Posts: 83
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Getting a year from a given date

Post 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.
[color=#800000][size=85][i][b]Munir Mdee
Software Developer (Data Processing)
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com[/b][/i][/size][/color]
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Getting a year from a given date

Post by josh »

Use the dateadd function.

dateadd(MYDATE, -1, "Y")

https://www.csprousers.org/help/CSPro/d ... ction.html
munirmdee1
Posts: 83
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: Getting a year from a given date

Post 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
[color=#800000][size=85][i][b]Munir Mdee
Software Developer (Data Processing)
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com[/b][/i][/size][/color]
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Getting a year from a given date

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