66
Views
9
Comments
Solved
is there any default function to get no. of days of the current year or any year?

is there any default function to get no. of days of the current year or any year? please suggest.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

That's quite easy:

DiffDays(NewDate(TargetYear, 1, 1), NewDate(TargetYear + 1, 1, 1))

DiffDays is a built-in function that returns the difference in days between two dates, NewDate is a built-in function that creates a date from year, month and day components. The difference in days of two consecutive 1 January dates is the number of days in the first year.

2024-03-05 10-18-49
RAHUL KUMAR

Hi @Priya Naveen 

You can get number of days between any specific period by using DiffDays(,) function available in OutSystems. It can be used in any expression.

For Example, For getting no. of days till today in current year, you can use days = DiffDays(#2024-01-01#,CurrDate())+1    // days = 134

2024-06-03 11-04-24
Priya Naveen

i want a functionlaity if give year as input it should give us number days for that year. suggest

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

That's quite easy:

DiffDays(NewDate(TargetYear, 1, 1), NewDate(TargetYear + 1, 1, 1))

DiffDays is a built-in function that returns the difference in days between two dates, NewDate is a built-in function that creates a date from year, month and day components. The difference in days of two consecutive 1 January dates is the number of days in the first year.

2023-10-21 19-42-11
Tousif Khan
Champion

Hello @Priya Naveen

You can simply check for a leap year, if the input year is a leap year then you can show 366 days else the year have 365 days.

To create a function create a client action and write your logic there and give an output that will return the days.

Here is how you can ,take any client action as a function  - 

You can also do the same to sever action if you have server side requirement.

attaching one example 

Thanks
Tousif Khan

Sample_Days.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

This is an overcomplicated answer, as you don't need to check for a leap year. Just use DiffDays.

2024-03-05 10-18-49
RAHUL KUMAR

Hi @Priya Naveen 

You can try that formula in expression to get the no of days in any year.

If((Mod(Year,4) = 0 and Mod(Year,100) >0 ) or (Mod(Year,400) = 0),366,365)

UserImage.jpg
Lavanya A

Hi @Priya Naveen 
1) There is no direct default function in outsystems to get the number of days in the year, but indirectly, you can achieve that with the existing function, if you are specifying a year alone, you can use Mod() function.

2) You can calculate the number of days between currdate() and required date() with the Diffdays() function. As @ RAHUL KUMAR mentioned, use DiffDays(#2024-01-01#,CurrDate())+1 and add both outputs to get a total number of days.

3) For better results, you can try different combinations of existing functions under date &time based on your requirements.

Check this Oml


Calculatenoofdays.oml
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Again, an overcomplicated answer. You do not use such complicated trickery. See my previous comment for the simplest solution.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.