cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Usernametwice23
Helper V
Helper V

How to compare now time and DateTimeValue in IF statement?

Hi all 

 

I have created an IF statement inside a collect which posts to dataverse as you can see below: 

Collect(
    'Time',
    {
        'Code': TextInputCode.Text,
        'Login Time': If(IsBlank(DefaultStartTime7am),Now();DateTimeValue("7:00 AM")),

    }
);

So if the label is blank then it will create a now() time for certain users while if not blank, it will say that the user started at 7am. 

 

I am trying to now figure out how I can add into this statement that if the user with a non blank label signs in past 7am, it will be recorded as now() instead of 7am. Im unsure how to add this into the syntax if someone could help me write this out. I have a feeling I would need to use greater or less than signs to accomplish this. 

 

Thanks so much for the help. Kind regards. 

1 ACCEPTED SOLUTION

Accepted Solutions
StalinPonnusamy
Super User
Super User

Hi @Usernametwice23 

 

Please try this

Collect(
    'Time',
    {
        'Code': TextInputCode.Text,
        'Login Time': If(IsBlank(DefaultStartTime7am) || (Now() > DateTimeValue("7:00 AM")),Now(),DateTimeValue("7:00 AM"))

    }
);

 
Thanks,
Stalin - Learn To Illuminate

View solution in original post

5 REPLIES 5
StalinPonnusamy
Super User
Super User

Hi @Usernametwice23 

 

Please try this

Collect(
    'Time',
    {
        'Code': TextInputCode.Text,
        'Login Time': If(IsBlank(DefaultStartTime7am) || (Now() > DateTimeValue("7:00 AM")),Now(),DateTimeValue("7:00 AM"))

    }
);

 
Thanks,
Stalin - Learn To Illuminate

Hi @StalinPonnusamy Thank you for your help. 

It seems to be stuck on the now() time. So it wont recognize that the current time is less than the DateTimeValue and keeps recording as now() when its meant to round up to 7am. 

'Login Time': If((DefaultStartTime7am.Text="Yes") || (Now() > DateTimeValue("7:00 AM")),Now(),DateTimeValue("7:00 AM"))

Thanks again for your help. 

 

AmeerJab
Resolver I
Resolver I

Hello,

 

you could use "Not" ex:

if(Not isBlank(), true, false)

 

Hope this help,

Regards.

Usernametwice23
Helper V
Helper V

Hi @AmeerJab  Thanks for your suggestion. 

 

'Login Time': If(IsBlank(DefaultStartTime7am.Text="Yes") || (Now() > DateTimeValue("7:00 AM")),Now(),DateTimeValue("7:00 AM"))

This works but I need to filter if the DefaultStartTime7am.Text="Yes" , so if it = "No" then the time should be now() instead of 7am  

StalinPonnusamy
Super User
Super User

Hi @Usernametwice23 

 

Looks like 7 AM should be

  1. When DefaultStart time is Yes
  2. If anyone logins before 7 AM

All other times should be the current time. 

 

If(DefaultStartTime7am.Text="Yes" || Now() < DateTimeValue("7:00 AM"),DateTimeValue("7:00 AM"),Now())

 

DefaultStartTime7am is a boolean field or Text field?


Thanks,
Stalin - Learn To Illuminate

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (2,083)