cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Spikyface
Advocate I
Advocate I

Display Current Year

I have a model driven app with a fairly simple request that I can't figure out how to implement without using Power Automate, which is out of scope for this app

 

I want to dynamically determine the current year when a record is created and save it as a field

 

If that's not possible, I just want to be able to display the current year on a form

 

Am I missing something very obvious or is this much harder than it sounds?

2 ACCEPTED SOLUTIONS

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @Spikyface :

  I'm afraid your request will not be fulfilled.I considered Create a Business rule or Add a Caculation filed.It is very easy to get the current time, but the current year cannot be obtained.

  The only way I can think of at the moment is to insert a canvas app in a form and then use Year(New()) to display the current year in this canvas app.

  If you want to display the current year directly in the form, I suggest you to post your ideal on the ideal forum.

Best Regards,

Bof

View solution in original post

Hi @Spikyface :

  I also considered using the DIFFINYEARS() function.

  The calculation method is to calculate the number of years between the current date and a specific date, and then you can know the current year. But it’s easy to get the current date, just use Now(), but it’s impossible to enter a specific date, because you cannot enter a date, such as 01/01/2015, as the Date value in a calculated column. Date and DateTime values can only be set or compared using other DateTime columns.

  I think this link will help:

 Define calculated columns in Power Apps - Power Apps | Microsoft Docs

 In addition the last way is to create or edit the form's web resources.This formula for your reference:

 

function test(executionContext) {
  var formContext = executionContext.getFormContext();
  var date = new Date();
  var year = date.getFullYear();
  formContext.getAttribute("crb5a_thecurrentyear").setValue(year.toString());
}

 

2.JPG

 

1.JPG

  Best Regards,

  Bof

View solution in original post

4 REPLIES 4
v-bofeng-msft
Community Support
Community Support

Hi @Spikyface :

  I'm afraid your request will not be fulfilled.I considered Create a Business rule or Add a Caculation filed.It is very easy to get the current time, but the current year cannot be obtained.

  The only way I can think of at the moment is to insert a canvas app in a form and then use Year(New()) to display the current year in this canvas app.

  If you want to display the current year directly in the form, I suggest you to post your ideal on the ideal forum.

Best Regards,

Bof

View solution in original post

Thanks for confirming this @v-bofeng-msft, unfortunately embedding a Canvas app into the form to do this is seems too much for this purpose

 

I did some experimenting around with a calculated field that uses the DIFFINYEARS() function but couldn't work out how to get it to return the current year.

 

Even then the field would always show the current year, even for older records so it seems like a fudge.

Hi @Spikyface :

  I also considered using the DIFFINYEARS() function.

  The calculation method is to calculate the number of years between the current date and a specific date, and then you can know the current year. But it’s easy to get the current date, just use Now(), but it’s impossible to enter a specific date, because you cannot enter a date, such as 01/01/2015, as the Date value in a calculated column. Date and DateTime values can only be set or compared using other DateTime columns.

  I think this link will help:

 Define calculated columns in Power Apps - Power Apps | Microsoft Docs

 In addition the last way is to create or edit the form's web resources.This formula for your reference:

 

function test(executionContext) {
  var formContext = executionContext.getFormContext();
  var date = new Date();
  var year = date.getFullYear();
  formContext.getAttribute("crb5a_thecurrentyear").setValue(year.toString());
}

 

2.JPG

 

1.JPG

  Best Regards,

  Bof

View solution in original post

lenro
Helper III
Helper III

Hi @Spikyface ,

 

I would create a variable where you need to put a date and call it VarYear,

Then put timer , button or whatever which is updating it as often as you need and put a formula to it 
Text(VarYear,"[$-en-US]yyyy")

If you don't need to update it , then instead of VarYear, just use Today()

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,920)