1
function today() private view returns (uint256) {
    return block.timestamp / 1 days;
}

Why do we need this function?

0

it will return how many days passed since 1/1/1970

1 days = 86400 second Epoch = 1531409238 second

Epoch/1 days= 17724 days, 15 hours, 26 minutes and 40 seconds.

This will help you to know in which day /date are you when we run this function 1970+17724 day

1

block.timestamp according to the Solidity documentation is current block timestamp as seconds since unix epoch.

days is a time unit built into Solidity

Dividing the time in seconds by 1 day worth of seconds returns you today

2
  • block.timestamp = 1 531 399 433 seconds 1 day = 86400 seconds 1 531 399 433 / 86400 = 17724.5304745 seconds Dividing the time in seconds by 1 day worth of seconds returns you today. What do you mean by "returns you today"?
    – axeism1in3
    Jul 12 '18 at 15:34
  • Every perfect 'day' since the Unix epoch can be represented as an integer. A 'perfect day' in this scenario is something with time exactly 00:00:00 The block timestamp 1 531 399 433 is not a perfect day. The integer part of the division, 17724, is the day since the unix epoch and the decimal part represents the specific time
    – Haardik
    Jul 12 '18 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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