Sign in to Community
Sign in to view all badges
I have a data element that is currently picking up values such as this:
Tue Oct 07 1975 00:00:00 GMT+0400 (Gulf Standard Time)
Tue May 05 1981 00:00:00 GMT+0400 (Gulf Standard Time)
I'd like to extract the YYYY [Char 11 - 15] from the text and then subtract from current year 2020 to get the age of the user. How can I accomplish this?
Case 1: 45 ... [2020 - 1975]
Case 2: 39 ...[2020 - 1981]
Edit: This is what I have so far but it doesn't load the data element.
QB: DOB is for example: Tue Oct 07 1975 00:00:00 GMT+0400 (Gulf Standard Time)
Here's what I think it should do:
1. Extract the 4 digits as string
2. Convert the 4 digit to integer
3. getFullYear to get 2020
4. Subtract the 4 digit integer from 2020 to pass the value to Adobe Analytics.
var x=_satellite.getVar('QB: DOB');var y= x.slice(11,15);return y;
Can anyone help with this.
var x=_satellite.getVar('dataLayer var: DOB'); var dobYear = x.getFullYear(); var curYear = new Date().getFullYear(); var age = curYear - dobYear; return age;