Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Create Function Field on Date Field to extract the Year

Renee-17
Tera Guru

I have a table that contains a date field.  I'd like to create a function field on that table that extracts the year from the date field.  I need this for reporting.  How can I accomplish this?  Is it possible?

 

I'd like to perform the same steps to also extract the month. 

1 ACCEPTED SOLUTION

Vasantharajan N
Tera Sage
Tera Sage

@Renee-17 - Please try with glidefunction:substring(sys_created_on,"1","4").

Note: I've used sys_created_on column to showcase the result. You can use your own column. 

VasantharajanN_2-1744105084549.png

 

Result 

VasantharajanN_3-1744105129782.png

 

 


Thanks & Regards,
Vasanth

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Renee-17 

 

https://www.servicenow.com/community/developer-forum/extract-month-year-from-date-into-a-string/m-p/...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Renee-17
Tera Guru

I've looked at these but don't see how I can use them to create a Function Field for a table.  I have to use glidefunction.  For example:

 

       glidfunction:substring(DisplayName,'1','4')

 

I'd like to replace DisplayName with Date and and just extract the year part of the date but date is not a text field so is there anyway of doing this via creating a function field?

 

 

Vasantharajan N
Tera Sage
Tera Sage

@Renee-17 - Please try with glidefunction:substring(sys_created_on,"1","4").

Note: I've used sys_created_on column to showcase the result. You can use your own column. 

VasantharajanN_2-1744105084549.png

 

Result 

VasantharajanN_3-1744105129782.png

 

 


Thanks & Regards,
Vasanth