Question

Display date field in month/year format



Dear all,

 

How can I display date field in month/year only when i pick a day?

Example:

I choose a day in "Date field": 23/01/2021

After that the display value in "Date field" is 01/2021



Best Regards,

Akira

Like 0

Like

8 comments

Hello Akira,

 

Neither Date nor Date\Time column won't allow storing date as month\year. So in your case you need to create a custom business process with a formula value that could read the data in the date\time column and then take month and date, concatenate them and return the result into a string column that allows storing date in such a way.

 

Best regards,

Oscar

Hi Oscar,

 

I already knew how to solve it by business process. But how about the UI? Instead of display only month/year after choosing date field, you create 01 or 02 fields to displays them???

Regards,

Akira

 

Phuong Akira,

 

You can create your custom method using getMonth() method in it. Please see an example of calling this method in JS here 

https://www.w3schools.com/jsref/jsref_getmonth.asp.

 

Best regards,

Oscar

Hi Oscar,

 

You mean that the date field display can show as the screenshot, right?

Regards,

Akira

 

Hello Akira,

 

Hope you're doing well.

Correctt, using of thу method mentioned by Oscar (getMonth() method) should help you to perform your business task.

 

Best regards,

Roman

Hi Oscar

 

Can you tell me what the logic is to extract the year part of the date out? There is a function for day, month and time but nothing (that I can see) for year?

 

Many thanks in advance

Rob Watson,

 

Hello,

 

You should use construction like dateTimeTest.Year.ToString() to get the year from your date\time (if we are discussing server-side logic). Something like (in Visual Studio):

DateTime dateTimeTest = DateTime.Now;
string yearPart = dateTimeTest.Year.ToString();
Console.WriteLine(yearPart);
Console.ReadKey();

The output is:

In business process (script-task or process methods) the approach is the same, but you need to put the "yearPart" string into some text parameter of the process to use it further.

 

If we are interested in the client-side logic then you need to use the getFullYear method (described here https://www.w3schools.com/jsref/jsref_getfullyear.asp).

Oleg Drobina,

many thanks

Show all comments