Read Year Part from UTC Datetime.

AdamKozmic-7665 45 Reputation points
2023-05-04T00:20:28.0866667+00:00

I've been struggling to figure out how to convert a datetime claim to a string. I've been reading https://learn.microsoft.com/en-us/azure/active-directory-b2c/date-transformations 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: https://learn.microsoft.com/en-us/azure/active-directory-b2c/date-transformations#getcurrentdatetime

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.

Thanks!

-Adam

Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
14,696 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alfredo Revilla (MSFT) 18,591 Reputation points Microsoft Employee
    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