web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to extract year fr...
Power Apps
Suggested Answer

How to extract year from DateTime field and convert to text value

(1) ShareShare
ReportReport
Posted on by
Need help, please, to convert the DOB (DateTime) year to text for use in Search function. I'm getting these errors from the Text function in my formula: 
 
 
If(!IsBlank(PTNameSearch.Value),Search('EMR PT Demographics', PTNameSearch.Value, 'Patient Name', Age, Text(DOB,"yyyy")),'EMR PT Demographics')
 
Thank you.
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,433 Super User 2025 Season 2 on at
    Hi
     
    What is DOB? I realize it probably stands for Data of Birth, but what i mean is, wherever you have this Text function it does not have access to anything called DOB.
     
    Its not a variable (at least on the same screen) or it would see it.
     
    So please share a picture or explain where DOB is set/value etc so we can help.
  • Suggested answer
    Nandit Profile Picture
    1,568 Moderator on at
    Hi, 
     
    I would suggest you take the datetime column out of the Search function and add a filter function for that like below. 
     
    Filter(
       Search('EMR PT Demographics', PTNameSearch.Value,
       'Patient Name', Age),
       PTNameSearch.Value = Text(Year(DOB))
    )
     
     
    If this answers your query, please mark this response as the answer.
    If its helpful, please leave a like. Thanks!
  • CU24081716-3 Profile Picture
    on at
    @FLMike - DOB (Date of Birth) is a DateTime column in the Sharepoint List 'EMR PT Demographics'
     
    I'm trying to build a search box for a gallery that allows searching on patient's name, birth year, age and ID. I'm having trouble converting the birth year and ID (which is the Sharepoint ID column) to text for them to work in my search.
     
     
    @Nandit - I put in the filter as you suggested, but the search no longer works even on Name or Age.
     
    Thank you both for jumping in to help.
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,433 Super User 2025 Season 2 on at
    Hi,
     
    Ahhh see if you have explained this (below underlined) I 
     
    I'm trying to build a search box for a gallery that allows searching on patient's name, birth year, age and ID. I'm having trouble converting the birth year and ID (which is the Sharepoint ID column) to text for them to work in my search.
     
    In the first place with the picture it would have been 100000000000000000000000000 times easier to help as I would have said.. its not supported. Seach Only works with strings. The reason for the error on DOB, is because you are typing in a Formula, where the Expression/Function Search requires a FIELD name, not a Value which is what you are trying to make it do.
     
    So that is why you need to use Filter for the Non-String Columns but you only have 1 Input, the text box.. what you need is the ability to let them type a string AND select a date and 1 for the ID as its a number or you have to create a couple of Outputs and Combine them
     
    1. Your Search
    2. A Filter on the Datasource where Date = (convert their string to date) OR ID = (concert their string to int). The issue is, you don't know if its a valid Date or a Valid ID, so you have to add extra code to check for that or you'll fail.
     
    Does your Gallery automatically get assigned (in the items) to the DataSource or do you have a Collection?
     
    Because you have to merge multiple "queries" Search + Filter to get what you want but they have to be done separately not together.
     
     
     
     
     
     
  • CU24081716-3 Profile Picture
    on at
    Sorry. Lesson learned on providing more details and background when asking for help.
     
    Thanks for your explanation and for outlining what must be done.
     
    I'm not using a Collection. Would a Collection make things easier for what I'm trying to do?
     
    The requirement to search on birth year has been dropped. I just need to search by Name, Age and ID.
     
    I can add another search box to just filter on ID, but how do I need to structure the formula on the gallery to make it work?
     
    Thank you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard