Updating User Profile Properties with the `Date no year` Format
When you set a User Profile property with PowerShell, and it has a format of Date no year
, how should you pass in the values? In other words, do you pass in the year, and it just gets lopped off or do you just pass in the day, like “November 10”?
In many cases you won’t actually care that much. But you should want to know how the values are stored so it doesn’t bite you later.
Out of the box, SPS-Birthday
is the only User Profile property which uses the Date no year
format. But you may decide to add others.
When you run a line of PowerShell like this, the value stored in the SPS-Birthday
field is “11/15/2001 12:00:00 AM”
Set-PnPUserProfileProperty `
-Account "[email protected]" `
-PropertyName "SPS-Birthday" `
-Value "11/15/2001"
When you run this next line (today), the value stored is “11/15/2022 12:00:00 AM”
Set-PnPUserProfileProperty `
-Account "[email protected]" `
-PropertyName "SPS-Birthday" `
-Value "November 15"
Note that the year stored is different in each case: 2001 vs. 2022.
We can prove that by checking the values afterward with this line:
Export-PnPUserProfile -LoginName "[email protected]"
In the user interface (UI), in both the cases above, the result is:
What this proves in the Date no year
format stores the value as a full date/time, but it is displayed without the year.
The reason this mattered to me was I was trying to use the PnP Modern Search Web Parts to display people with birthdays today. To do that, I needed to filter on a Managed Property mapped to the People:SPS-Birthday
Crawled Property.
Once the RefinableDate02
Managed Property was set up, I could add a query like this:
RefinableDate02:"2022-{CurrentMonth}-{CurrentDate}T00:00:00Z"
Note that the year needs to be a constant in order for the filter to work. We might have two people with birthdays on November 15, but in the years 1954 and 2001. If we store the actual year with in the SPS-Birthday
property, then our filter can’t work: there’s no wildcard-type mechanism in KQL we can use to say “ignore the year”. In the old DOS days, we could do something like: ????-{CurrentMonth}-{CurrentDate}T00:00:00Z
to say “any four characters”, but KQL doesn’t support that.
So, the key here is to choose a year and set all the birthdays to have that constant year. In this case, we chose 2000. This also ensures data privacy, as someone with a little PowerShell knowledge could retrieve people’s “real” birthdays.
If we didn’t choose a constant year, but instead passed in “November 15” and expected that the year wasn’t stored, our filter would break when 2023 rolls around.
The filter ended up looking like this:
RefinableDate02:"2000-{CurrentMonth}-{CurrentDate}T00:00:00Z"
Now we’ve got a working solution which is robust enough to last over the years. A little detective work was well worth the effort.
This is *exactly* what I’ve been trying to figure out how to do today. My company has been relying on a dedicated list of employee info for several years instead of using direct queries to the user profile service, and this is one of the few remaining things that needs to be switched over. Thank you so much for this post!