Forum Discussion
QuickBaseCoachD
8 years agoQrew Captain
:)
Right, I missed that ...
If(
$isSunday,ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time]))),2),ToTimeOfDay("8 pm"))),
$isSaturday,ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time]))),3),ToTimeOfDay("8 pm"))),
$isFriday and $isFridayEightPM,ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time]))),4),ToTimeOfDay("8 pm")),
$isFriday and not $isFridayEightPM, ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])),2)),ToTimeOfDay([Date Time])))
)
There may be unbalanced brackets. I did not try to reconcile the closing ))) at the end of each line.
Note that with Quick Base, unlike Excel, you do not need to next your IFs. You can just start with one IF( and then list all your tests and results below in sequence.
That last ) at the end by itself is the closing to the beginning ( of the IF.
Right, I missed that ...
If(
$isSunday,ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time]))),2),ToTimeOfDay("8 pm"))),
$isSaturday,ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time]))),3),ToTimeOfDay("8 pm"))),
$isFriday and $isFridayEightPM,ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time]))),4),ToTimeOfDay("8 pm")),
$isFriday and not $isFridayEightPM, ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])),2)),ToTimeOfDay([Date Time])))
)
There may be unbalanced brackets. I did not try to reconcile the closing ))) at the end of each line.
Note that with Quick Base, unlike Excel, you do not need to next your IFs. You can just start with one IF( and then list all your tests and results below in sequence.
That last ) at the end by itself is the closing to the beginning ( of the IF.
- RachelJones8 years agoQrew CadetI was having trouble understanding how to format multiple if/then statements. I tried without nesting the ifs and the syntax worked but the logic was wrong. I will try again, but my biggest issue is that I am trying to check sequentially first, is it friday after 8pm? Then if it's not, i want to know if it's friday at all (before 8pm). Finally if neither of those are true, i want to check for the other conditions. That's why nested ifs make sense to me but the other structure was confusing.
I did not know I could do "and not". That is exactly what I needed. Thanks. I think this is the missing link. - QuickBaseCoachD8 years agoQrew CaptainOK, post back if you are stuck. You should be able to do this with just one IF, and then a series of tests and results. Quick Base will take the first one which is true.
Here is the help for the IF, which is different from Excel's IF
https://login.quickbase.com/db/6ewwzuuj?a=dr&r=cm&rl=cwd
Here is a list of all the functions.
https://login.quickbase.com/db/6ewwzuuj?a=q&qid=6 - QuickBaseCoachD8 years agoQrew CaptainHere is an example of an IF with several tests. You will see that the IF is not nested.
https://login.quickbase.com/db/bcgahn76w?a=dr&r=bm&rl=cwe - RachelJones8 years agoQrew CadetIt's working! There were other syntax errors, but fixing my understanding of how to properly do the multiple if/then statement allowed me to easily work out the rest of the issues.
<pre>
//what day of the week is it? set variables for significant days: Friday, Saturday, & Sunday
var number day = DayOfWeek(ToDate([Date Time]));
var bool isFriday = If($day=5,true);
var bool isSaturday = If($day=6,true);
var bool isSunday = If ($day=0, true);
//workday ends at 8pm Friday, so things submitted 8pm and later are considered next day
var bool isFridayEightpm = If($isFriday=true and ToTimeOfDay([Date Time])>=ToTimeOfDay("8 pm"),true);
//if a task is submitted Friday 8pm until Sunday 11:59 pm, make it due Monday 8pm
//otherwise, task is due next day, same time (24 hrs)
//in order to add the right number of days to the original timestamp, we have to check for Fri, Sat, and Sun separately
If(
$isSunday,
ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])), 2)), ToTimeOfDay("8 pm")),
$isSaturday,
ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])), 3)), ToTimeOfDay("8 pm")),
$isFriday and $isFridayEightpm,
ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])), 4)), ToTimeOfDay("8 pm")),
$isFriday and not $isFridayEightpm,
ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])), 2)), ToTimeOfDay([Date Time])),
ToTimestamp(ToDate(WorkdayAdd(ToWorkDate(ToDate([Date Time])), 2)), ToTimeOfDay([Date Time]))
)
</pre>
And here is evidence the logic also works: http://take.ms/ZGtLG
THANK YOU! - QuickBaseCoachD8 years agoQrew Captain:) // and I love the comments too.