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

5 REPLIES 5
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

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

lenro
Helper IV
Helper IV

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()

Where is the function placed?  Does it go in the application, sharepoint calculated field, or is this some other platform?

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

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