Question

regex to extract year from date in L* format


Userlevel 2
Badge +4

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


3 replies

Userlevel 4
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 2
Badge +4

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 4
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. 

Reply