How to /testfor time with command block in 1.8? Screenshots would be nice, if possible.

  • 1
    Have you made any attempts to do this yourself? Is a daylight sensor not viable for your specific problem? Why (i.e. describe what you want to achieve)? We are not a "build-your-command"-website, and we like to see people put effort into a question before putting effort into answers. – MrLemon Feb 10 '16 at 9:06

This can be achieved with /stats and /time.

First, you'll need to set up a scoreboard objective and an armor stand to store the time.

/scoreboard objectives add time dummy
/summon ArmorStand ~ ~ ~ {CustomName:"time",Marker:1b,Invisible:1b}
/scoreboard players set #MATH time 24000

The third command here simply stores a value of 24000 in a fake player called #MATH, which we'll need later.

Set up a clock, such as a fill clock, and have it run two commands:

/time query daytime
/scoreboard players operation @e[type=ArmorStand,name=time] time %= #MATH time

The second command makes it so that time resets to 0 after a full day, rather than keep going indefinitely.

Finally, stand on top of the /time command block and run

/stats block ~ ~-1 ~ set QueryResult @e[name=time,type=ArmorStand] time

You can now access the time in a target selector like any other scoreboard value, e.g.:

/testfor @e[type=ArmorStand,name=time,score_time=18000,score_time_min=18000]

to test for midnight.

  • 1
    The target for /stats can only resolve to 1 target, thus cannot be @a for a multiplayer environment. You could instead have it target a fake player (such as /stats X Y Z set QueryResult #NAME time) and use /scoreboard players test #NAME time 18000 18000 to check the score. Alternatively, it could be set to a dummy entity like an armor stand, allowing you to use /execute and other commands off of it. – Skylinerw Feb 10 '16 at 15:47
  • @Skylinerw Thanks, didn't know that. I changed it to use an invisible armor stand instead. – MrLemon Feb 10 '16 at 18:20
  • This is what i need thx bro! – blueguys1 Feb 11 '16 at 3:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.