Question

Extract Year from Date field

There is a function to create a month and day field from a date but there does not seem an option to create a year field from a date. Does anyone know the best way to achieve this?

Like 0

Like

3 comments

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

Thank you for this solution Mira!

I used the same technique with the Low Code settings to achieve the same result. I parsed the current year from the current date to use as a parameter in the process. Very helpful.

Susan Samara,

Hi Susan,

 

I'm use the following approach

 

[#System variable.Current Date#].ToString("yyyy")

 

If you need the result as integer, can use:

 

Convert.ToInt32([#System variable.Current Date#].ToString("yyyy"))
Show all comments