Read Year Part from UTC Datetime.

AdamKozmic-7665 60 Reputation points

I've been struggling to figure out how to convert a datetime claim to a string. I've been reading and it doesn't look like there's any way to do it.

My end goal is to Get the YEAR component off of the current date and time. I was thinking I would generate the current date time, convert to a string, and then use a RegEx claims resolver to read the year.

I can generate the DateTime with this:

For example, if the GetCurrentDateTime returns 2022-01-14T11:40:35.0000000Z, I'd want to set a claim value to be 2022

It will not allow me to do string operations off of it because the claim is of type dateTime

Any help would be much appreciated.



Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,187 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. 2023-05-08T03:14:04.4566667+00:00

    Hello @AdamKozmic-7665 , as you already found, you cannot apply string transformations to a date or datetime claim. You can, however, develop a custom API just for this purpose and consume it from your custom policy. For more information take a look to Calling a RESTful service.

    Let us know if you need additional assistance. If the answer was helpful, please accept it and rate it so that others facing a similar issue can easily find a solution.

    0 comments No comments