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
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

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

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

<
Users online (4,415)