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?

1
  • 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, 2021 at 11:41

1 Answer 1

1

Your function will always return true

You need to rely on external parameters

2
  • 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. Jun 18, 2021 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, 2021 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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