6/21/2023 0 Comments Groovy date minus minutesMaybe this will get added in a subsequent update, but for now, using Excel.DATEDIF function is best suited for the number of days or years only. Println (Excel.DATEDIF(dateMinus, datePlus, DateUnit.YEARS))Ä®xcel supports many types of date units, but somehow a very basic unit like DateUnit.MONTH isn't available. ![]() this function assumes the first date is earlier than the second Let's see how we use Excel to help with Date manipulations println (Excel.DATEDIF(dateMinus, datePlus)) ![]() This isn't strictly part of Groovy but we have an additional capability of leveraging Excel functions in EPBCS. The 15th of the month is different in Feb than it is in Dec.Ä®xplore the GregorianCalendar class to learn and explore more. This could help with much more precise calculations if you need what percentage of days is represented by the current date with respect to the total days of the month. Println (cal.getActualMaximum(Calendar.DAY_OF_MONTH)) println (cal.getActualMinimum(Calendar.DAY_OF_MONTH)) You could also get other useful information like the first day of the month (not very helpful because it is always 1), but you can get the last day of the month. So adding months is significantly easier with the "add" function and specifying the field, just that you would need to first create a Calendar object. keeping in tradition with the default date format Println (cal.format("EEE MMM dd hh:mm:ss z yyyy")) GregorianCalendar cal = new GregorianCalendar()Ĭal.setTime(new Date().parse("yyyy-MMM-dd", "2022-Dec-05")) More specifically the GregorianCalendar class (as Calendar is an abstract class). If you need to add months or years, then you would need the Calendar class. The date class is limited in its ability to do other types of arithmetic than taking differences in dates, or intervals, or adding/subtracting days. Äef dayDifference = (dateMinus. ![]() One common situation you'll come across is when you're parsing the date from Year / Month dimension member names. "yyyy", "yy", "mm", "MMM", "d", and "dd" are the most common formatting patterns you'll need. Here's a complete list of the formatting patterns You can type in the date as the second argument, or pass a variable that refers to a date in a String format. The first part of the string defines the format in which we expect the date to be. Parsing Dates Date parseDate = new Date().parse("yyyy-MMM-dd", "2022-Dec-09") Println date // output: Sat Jan 15 00:00:) ![]() You can also initialize the date when creating the object by passing in the year, month, and day as arguments. That's it, you now have a Date object initialized to the current time. Creating Dates Date newDateObj = new Date() To let your creativity take full advantage, let's see what we can do with the Date class. pro-rating a new hire's salary using the date of hire and calculating the precise number of working days for the first month). With Groovy, using the Date class allows you to deliver functionality that you wouldn't have been able to do so with Essbase scripts (e.g. The Date object in Groovy provides a simple and intuitive way to work with dates and times in your code. One of the most useful features of Groovy is the built-in support for working with dates and times. Groovy is a powerful and versatile programming language that offers a wide range of features for developers. Usually, we limit ourselves to the Year and Month, and assume the calculation logic for the entire month and call it a day. Mastering Date Functions in Groovy for EPM Planning ScriptsÄate functions are the hardest to manipulate in Essbase scripts.
0 Comments
Leave a Reply. |