Try adding an additional bit of logic for the minutes:
IF DATEPART('hour',[MyDate]) >= 6 AND DATEPART('minute',[MyDate]) >= 30 THEN something END
You need to learn how Tableau 'thinks'. So this works:
IF DATEPART('hour',[MyDate]) >= 6
Now you want it to be 6:30, right?
IF DATEPART('hour',[MyDate]) >= 6 AND DATEPART('minute',[MyDate]) >= 30 THEN ....
You need to break it all down into parts, Tableau (and most software) don't read time/dates without a lot of help.
I think this is what you are looking for:
Just replace NOW() with your datetime. The result of this will be a single number that represents the hour. 6:30 will end up as 6 if am and 18 if pm.
I thought about that, but is not working. Looks like is selecting all events happened after 6:30 AM, and every other hour, past 30 minutes, but not before. Looks weird.
Can you elaborate more on that one? What should I use for comparison?
What I need is a way to select a range. It should be something like:
IF [MyDate] >= "06:30" AND [MyDate] <= "18:30" THEN "Day" ELSE "Night" END
I have attached a full sample of what I think you are looking for. If its not quite correct just let me know.
I started by creating two parameters. One for the start time and one for the end time. I just have them as Date & Time format as I was too lazy to figure out how to get that to change... If its critical let me know and I'll try and fix it.
From there I took the date & time in my data set as well as the start and end times and converted them to decimals in order to create an easy and straightforward calculated dimension to pull it all together. The calculation is as follows:
INT(DATEPART("hour",[Date])) + INT(DATEPART("minute",[Date]))/60
That final calculated dimension is called "Time of Day Indicator" and is simply defined as the following:
IF [Time Decimal] >= [Start Time Decimal] AND [Time Decimal] <= [End Time Decimal] THEN
Hope that helps!
Time Comparisons Sample.twbx 33.0 KB