34
Views
5
Comments
Solved
Check time range
Question
Application Type
Reactive

Hi all,

I need check if current date is between 1st may last year and 31 mar this year, if true will get data if false do nothing.

How can I check the time range?

2020-07-21 19-28-50
Rajat Agrawal
Champion
Solution

Hi @Bella Nguyen 

You are also doing like this

Regards ,

Rajat

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

@Bella Nguyen ,

I think you asked your question in a bit of an unfortunate way.  I'm assuming you want to check whether a date is inside a "season", that possibly can cross the year-end.

If you really want to check if CurrentDate is bigger than a date, any date, of last year, well of course it always is.  So in your example dates, I think you mean that for example a day in september or a day in january is within range, but a day in april is not.

Is that the case ?

@Nuno Reis and @Rajat Agrawal

1° I don't get why DiffHours or DiffDays is used, why not just compare dates.

2° the first part of your conditions is always true, currDate is always larger than a startdate, any startdate, of the year before.


Assuming I understood the question : The question looks deceptively easy, and in our brain, it takes almost no thinking energy.  But sticking with OutSystems functions, and trying to solve in a single line, is not that obvious.

Here's a possible way : make all dates in the same year, and then apply a different condition depending on whether the first day of the range is earlier or later in the year than the last day

I like to do stuff in steps, but you can do it in a single line (like in an expression on a screen :


I just picked a year I like, but probably to be sure it works in all cases, you should pick a leap year.

Dorine

2016-04-22 00-29-45
Nuno Reis
 
MVP

Answering to your part 1: force of habit after some DST and Timezone issues. Any other date compare function will do.

Answer to part 2: I'm assuming this is some fiscal year validation. My brain thought on a generic solution for any date and then replaced by CurrDate() as requested. Looking at it now that you mention it, I'll just dig a hole and disappear.

2016-04-22 00-29-45
Nuno Reis
 
MVP

Hello Bella.


That is a very easy question.

your condition is May2024 < Today and Today < Mar 2025


You need to create the date 2024-05-01 and compare it to today. I'm using DiffHours that will return hours since Date1 until Date2 (If hours are 0 or positive, Date1<=Date2). Then the same for 2025-03-31.


DiffHours(NewDate(Year(CurrDate())-1,5,1), CurrDate() ) >= 0

and

DiffHours(CurrDate(),NewDate(Year(CurrDate()),3,31) ) >= 0


Notice that I got the current year and subtracted 1 to be last year's May.


Place this inside an If and you are ready to go.

2020-07-21 19-28-50
Rajat Agrawal
Champion
Solution

Hi @Bella Nguyen 

You are also doing like this

Regards ,

Rajat

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

@Bella Nguyen ,

I think you asked your question in a bit of an unfortunate way.  I'm assuming you want to check whether a date is inside a "season", that possibly can cross the year-end.

If you really want to check if CurrentDate is bigger than a date, any date, of last year, well of course it always is.  So in your example dates, I think you mean that for example a day in september or a day in january is within range, but a day in april is not.

Is that the case ?

@Nuno Reis and @Rajat Agrawal

1° I don't get why DiffHours or DiffDays is used, why not just compare dates.

2° the first part of your conditions is always true, currDate is always larger than a startdate, any startdate, of the year before.


Assuming I understood the question : The question looks deceptively easy, and in our brain, it takes almost no thinking energy.  But sticking with OutSystems functions, and trying to solve in a single line, is not that obvious.

Here's a possible way : make all dates in the same year, and then apply a different condition depending on whether the first day of the range is earlier or later in the year than the last day

I like to do stuff in steps, but you can do it in a single line (like in an expression on a screen :


I just picked a year I like, but probably to be sure it works in all cases, you should pick a leap year.

Dorine

2016-04-22 00-29-45
Nuno Reis
 
MVP

Answering to your part 1: force of habit after some DST and Timezone issues. Any other date compare function will do.

Answer to part 2: I'm assuming this is some fiscal year validation. My brain thought on a generic solution for any date and then replaced by CurrDate() as requested. Looking at it now that you mention it, I'll just dig a hole and disappear.

UserImage.jpg
Bella Nguyen

thank you all, I solved my issue with NewDate().

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