1

I want to make sure that the block.timestap that keep on running is represent today's date. I can get from this code but not really sure is this the right way.

function isTodayDate() view public  returns(bool) {
  uint _block = block.timestamp;

  uint _today = _block + 1 days - 1 days;

  return (_block == _today);

}

Is there another better right code?

  • You will need external information as arguments in your function, such as the timestamp of today or something similar, since the EVM does not have mechanisms to calculate dates. – alberto Jun 17 '21 at 11:41

1 Answers1

1

Your function will always return true

You need to rely on external parameters

zmy
  • 376
  • 1
  • 6
  • Rely on external meaning get input from external. When I deploy my contract and verify then people can enter any number from the 'public' parameter. – Sulung Nugroho Jun 18 '21 at 21:32
  • I don't know where you want to use this, maybe you can implement it in a different way. For example, save the current time and read the comparison between the last time and the current time in the next verification time. I don't know whether this can meet your requirements? – zmy Jun 21 '21 at 10:35