web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / If Date is in between ...
Power Apps
Answered

If Date is in between dates of SPO Column - run this code, otherwise run other code

(0) ShareShare
ReportReport
Posted on by Microsoft Employee
I was planning on creating two seperate date columsn in SPO. StartTime and EndTime columns. I want to setup my app so that if the date is between those two dates, it runs a specific set of code. If not, it runs the other.
 
So I want to grab those two columns, check the current date, if the current date falls between the dates in the Start and End columns, then run this code:
If(CurrentTimeZone.Text = "UTC-7:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-2)));
If(CurrentTimeZone.Text = "UTC-6:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-1)));
If(CurrentTimeZone.Text = "UTC-5:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,0))));
If(CurrentTimeZone.Text = "UTC-4:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,1))));
 
If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
If(CurrentTimeZone.Text = "UTC-4:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'));
 
if it is not, then run this code:
If(CurrentTimeZone.Text = "UTC-8:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-2)));
If(CurrentTimeZone.Text = "UTC-7:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-1)));
If(CurrentTimeZone.Text = "UTC-6:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,0))));
If(CurrentTimeZone.Text = "UTC-5:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,1))));
 
If(CurrentTimeZone.Text = "UTC-8:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'));
 
There are a ton of if statements, so I was not sure how to combine all of this.
(FYI, I have played with this for a week, the way our SPO site was built and set to Central, this is the best I can come up with).
Categories:
  • BCBuizer Profile Picture
    22,899 Super User 2026 Season 2 on at

    Hi @lardo5150 ,

     

    The check if the current date is between the start and end date can be done along the lines of the below:

     

    If(Now()>=Start.SelectedDate And Now()<=End.SelectedDate,
     "Between Start and End",
     "Before Start or after End"
    )

     

    As for your ton of If statements, perhaps you want to consider a Switch() and nest it in the Set() instead of the other way around:

     

    Set(var_hours,ForAll(
     var_AssignmentHours,Sum(Value) Switch(
     CurrentTimeZone.Text,
     "UTC-7:00", -2,
     "UTC-6:00", -1,
     "UTC-5:00", 0,
     "UTC-4:00", 1
     )
     )
    )
  • lardo5150 Profile Picture
    Microsoft Employee on at

    @BCBuizer 

    How would that look if I am checking whether to run code section 1 if between these dates, and code section 2 if not?

     

  • BCBuizer Profile Picture
    22,899 Super User 2026 Season 2 on at

    Hi @lardo5150,

     

    You can just replace the samples I gave with your code to start with. Multiple commands can be run as long as you use a semicolon as a separator:

     

    If(Now()>=SPO.StartTime And Now()<=SPO.EndTime,
    
     If(CurrentTimeZone.Text = "UTC-7:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-2)));
     If(CurrentTimeZone.Text = "UTC-6:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-1)));
     If(CurrentTimeZone.Text = "UTC-5:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,0))));
     If(CurrentTimeZone.Text = "UTC-4:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,1))));
     
     If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
     If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
     If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
     If(CurrentTimeZone.Text = "UTC-4:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'))
    
     ,
    
     If(CurrentTimeZone.Text = "UTC-8:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-2)));
     If(CurrentTimeZone.Text = "UTC-7:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value)-1)));
     If(CurrentTimeZone.Text = "UTC-6:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,0))));
     If(CurrentTimeZone.Text = "UTC-5:00",Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,1))));
     
     If(CurrentTimeZone.Text = "UTC-8:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
     If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
     If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
     If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'))
    
    )

     

     

     

  • lardo5150 Profile Picture
    Microsoft Employee on at

    @BCBuizer 

    Any idea what I am doing wrong here?

    lardo5150_0-1646309951293.pnglardo5150_1-1646309971496.png

     

  • lardo5150 Profile Picture
    Microsoft Employee on at

    @BCBuizer 

    I was able to figure out the code.

    If(Today()>=var_engineer.DSTstart And Today()<=var_engineer.DSTend,
    Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,Switch(CurrentTimeZone.Text,
    "UTC-7:00", -2,
    "UTC-6:00", -1,
    "UTC-5:00", 0,
    "UTC-4:00", 1
    )
    )
    )
    );
    ,
    Set(var_hours,ForAll(
    var_AssignmentHours,Sum(Value,Switch(
    CurrentTimeZone.Text,
    "UTC-8:00", -2,
    "UTC-7:00", -1,
    "UTC-6:00", 0,
    "UTC-5:00", 1
    )
    )
    )
    )
    );

     

    Is it possible to do something similar with the following block of code?  I did not know how to do it since for each if, I am calling a different SPO column.

     

    If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
    If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
    If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
    If(CurrentTimeZone.Text = "UTC-4:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'));

     

    If(CurrentTimeZone.Text = "UTC-8:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
    If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
    If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
    If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'));

  • lardo5150 Profile Picture
    Microsoft Employee on at

    Here is the full example.  Can we reduce the IF statements in that piece?

     

    If(Today()>=var_engineer.DSTstart And Today()<=var_engineer.DSTend,
    Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,Switch(CurrentTimeZone.Text,
     "UTC-7:00", -2,
     "UTC-6:00", -1,
     "UTC-5:00", 0,
     "UTC-4:00", 1
     )
     )
    )
    );
    If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
    If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
    If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
    If(CurrentTimeZone.Text = "UTC-4:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'));
    ,
    Set(var_hours,ForAll(
     var_AssignmentHours,Sum(Value,Switch(
     CurrentTimeZone.Text,
     "UTC-8:00", -2,
     "UTC-7:00", -1,
     "UTC-6:00", 0,
     "UTC-5:00", 1
     )
     )
    )
    );
    If(CurrentTimeZone.Text = "UTC-8:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Pacific'));
    If(CurrentTimeZone.Text = "UTC-7:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Mountain'));
    If(CurrentTimeZone.Text = "UTC-6:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Central'));
    If(CurrentTimeZone.Text = "UTC-5:00",Set(var_EngineerQueueTime,var_engineer.'QueueShift-Eastern'));
    );
  • BCBuizer Profile Picture
    22,899 Super User 2026 Season 2 on at

    Hi @lardo5150 ,

     

    Please give the below a go:

     

    If(Today()>=var_engineer.DSTstart And Today()<=var_engineer.DSTend,
    	Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,Switch(CurrentTimeZone.Text,
    			 "UTC-7:00", -2,
    			 "UTC-6:00", -1,
    			 "UTC-5:00", 0,
    			 "UTC-4:00", 1
    			 )
    		 )
    		)
    	);
    	Set(var_EngineerQueueTime,var_engineer. Switch(CurrentTimeZone.Text,
    		"UTC-7:00",'QueueShift-Pacific',
    		"UTC-6:00",'QueueShift-Mountain',
    		"UTC-5:00",'QueueShift-Central',
    		"UTC-4:00",'QueueShift-Eastern'
    		)
    	),
    	Set(var_hours,ForAll(
    	 var_AssignmentHours,Sum(Value,Switch(
    				CurrentTimeZone.Text,
    				"UTC-8:00", -2,
    				"UTC-7:00", -1,
    				"UTC-6:00", 0,
    				"UTC-5:00", 1
    				)
    			)
    		)
    	);
    	Set(var_EngineerQueueTime,var_engineer. Switch(CurrentTimeZone.Text,
    		"UTC-8:00",'QueueShift-Pacific',
    		"UTC-7:00",'QueueShift-Mountain',
    		"UTC-6:00",'QueueShift-Central',
    		"UTC-5:00",'QueueShift-Eastern'
    		)
    	)
    )

     

  • lardo5150 Profile Picture
    Microsoft Employee on at

    This failed.  I tried to rework it but no go either.

     

    lardo5150_0-1646335874045.pnglardo5150_1-1646335908480.png

     

  • Verified answer
    BCBuizer Profile Picture
    22,899 Super User 2026 Season 2 on at

    Hi @lardo5150 ,

     

    Take 2:

     

    If(Today()>=var_engineer.DSTstart And Today()<=var_engineer.DSTend,
    	Set(var_hours,ForAll(var_AssignmentHours,Sum(Value,Switch(CurrentTimeZone.Text,
    			 "UTC-7:00", -2,
    			 "UTC-6:00", -1,
    			 "UTC-5:00", 0,
    			 "UTC-4:00", 1
    			 )
    		 )
    		)
    	);
    	Set(var_EngineerQueueTime, Switch(CurrentTimeZone.Text,
    		"UTC-7:00",var_engineer.'QueueShift-Pacific',
    		"UTC-6:00",var_engineer.'QueueShift-Mountain',
    		"UTC-5:00",var_engineer.'QueueShift-Central',
    		"UTC-4:00",var_engineer.'QueueShift-Eastern'
    		)
    	),
    	Set(var_hours,ForAll(
    	 var_AssignmentHours,Sum(Value,Switch(
    				CurrentTimeZone.Text,
    				"UTC-8:00", -2,
    				"UTC-7:00", -1,
    				"UTC-6:00", 0,
    				"UTC-5:00", 1
    				)
    			)
    		)
    	);
    	Set(var_EngineerQueueTime, Switch(CurrentTimeZone.Text,
    		"UTC-8:00",var_engineer.'QueueShift-Pacific',
    		"UTC-7:00",var_engineer.'QueueShift-Mountain',
    		"UTC-6:00",var_engineer.'QueueShift-Central',
    		"UTC-5:00",var_engineer.'QueueShift-Eastern'
    		)
    	)
    )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 232 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 202 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard