Solved

regex to extract year from date in L* format


Userlevel 3
Badge +5

Hi all,

I'm currently struggling when trying to extract the Year from my createdAt property. Can someone give me a hint on how to get the createdAt year?

If I can extract the year I will be able to get the account age.

Best regards,

 

Bernardo Madeira

icon

Best answer by jonathan 20 May 2022, 03:04

View original

4 replies

Userlevel 5
Badge +3

@bernardo.madeira Assuming your createdAt property is ISO 8601 format (i.e 2022-05-19 etc) then the regex to extract the 4 digit year would be (\d{4}).

e.g.

 

Userlevel 3
Badge +5

Hi Jonathan,

Thank you once again. My createdAt field is in datetime format. The regex code you shared with me works, however I think it would be helpful if we could have a today() timestamp functionality in Heap to keep account age segmentation dynamic.

The regex code is in JS right? Can you please share the additional code to use if we want to extract Year and Month?

I'm trying to use  code below but it's not working.

(\d{4})/\(\d{1,2})
Userlevel 5
Badge +3

I think it would be helpful if we could have a today() timestamp functionality in Heap to keep account age segmentation dynamic.

 

100%. I mentioned that on the other thread about account age. That, plus native handling of Date data types is exactly what we need to make this a properly supported use case. 

 

Can you please share the additional code to use if we want to extract Year and Month?

 

Given the datetime format i.e. YYYY-MM-DD etc then \d{4}-\d{2} will work. 

Badge

Hey @jonathan,

 

How do I change the property to make it  ISO 8601 format? I am in a similar situation where I have user registered date property via Custom API. Data type is set to Autodetect, date pulled is in the format of “April 22, 2018”. How can I make it 2018-04-22 so that I can pull YY-MM using regex expression?

 

Thanks in advance,

Gaurav

Reply