Suppose I am running a gallery and ask participants to submit there paintings before a specific date. After passing that date participant should not be able to submit their entry. How can I implement such functionality?
There are two ways to do this:
1) Limit the deadline by the block number.
require(block.number < 7169670); // Where 7169670 is a block number.
2) Limit the deadline by the current timestamp.
require(now < 1549219795); // Where 1549219795 is the current unix timestamp.
There are advantages for both. It is not recommended to use block.number
for checks that are in a long time, as there is variance in timing of blocks and other factors such as the ice age.
now
is preferred, as it is generally more accurate. With each mined block, miners include a timestamp of the current time. There are rules which limit their ability to manipulate this time (for example, it cannot be prior to the previous block's timestamp, nor can it be too much longer than it).