You are viewing limited content. For full access, please sign in.

Question

Question

How do I get just the year of the birth date to appear when the full birthdate is the data?

asked on September 13, 2021 Show version history

I am auto-filling a form with a client's birthdate and I want only the year to appear. 

The current data appears for example as 7/3/2021 - how do I get the 4 digits from the year to only appear and without the / as I have just 4 boxes to populate?

I've managed to separate the month and day but not the year using a regular expression. For the month (\d+) and then the day /(\d+)/  so what can I use for the year?

0 0

Answer

SELECTED ANSWER
replied on September 13, 2021 Show version history

EDIT: Reading the post again it seems I may have misunderstood. I assumed you were talking about Forms, but are you doing this in a fillable PDF or something through workflow? If so, then you could just use the Token Editor (right-click, token editor) and date formatting like so,

 

Instead of relying on regular expressions or anything, I'd add 2 fields, one Date field to store the full date of birth pulled from the lookup, and one Number or Single Line to hold the year (depending on how you may need to use the value).

If you use a Number, be sure to uncheck the box for comma-separated thousands and that the decimal length is set to zero.

Use field rules to hide the date of birth field and set it it to read only, then in your "birth year" field, use a function to extract the year from the hidden date of birth field.

 

Alternatively, you could create a SQL view that just adds a "Birth Year" column that converts it on the database side, which is what I would do in some other scenarios.

CREATE VIEW [v_myview] AS
SELECT *, 
    DATEPART(YEAR,[DateOfBirth]) AS [BirthYear]
FROM [dbo].[mytable]

Something like that would return all the normal columns from the table, plus an additional column with the birth year already extracted.

1 0
replied on September 13, 2021

Thank you, sorry my question wasn't clear enough but yes the workflow answer worked great! 

0 0

Replies

replied on September 13, 2021

Francesca,

You should be able to extend your current regex to \d+/\d+/(\d+) to pull the year from a date.  (Assuming that the date is always in the M/d/yyyy format)

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.