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

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

Show all comments