0

I am very new to solidity and stack exchange as well. I am trying to use the date time api from https://github.com/pipermerriam/ethereum-datetime/tree/master/contracts. What getYear(date) does is that it takes an argument date and returns the year of the date. I am trying to save the returned value of getYear() to a variable requiredYear like I do in Java or C++. The truffle compiler is giving me other errors so I cannot tell whether this is correct, but I was also not able to find any documentation about it. Any help would be appreciated!

 uint16 requiredYear = getYear(uint dateStampOfMileStone) constant returns (uint16);
  • 1
    If you have a working example in either one of these two languages, then you can probably see that it looks more or less like this: uint16 requiredYear = getYear(x);, where x is a constant or an expression. – goodvibration Aug 4 at 6:31
  • @goodvibration thank you for the response. I changed it the way you wrote it, but I'm getting an error "ParserError: Expected ',' but got identifier" on that line. My code reads uint16 requiredYear = getYear(uint dateStampOfMileStone); and the error points to `dateStampOfMileStone' – Eric Aug 6 at 3:06
  • That's NOT how I wrote it!!! – goodvibration Aug 6 at 3:48
  • All I did is plug in unit dateStampOfMileStone in x – Eric Aug 8 at 1:25
  • like I do in Java or C++ - is that how you really do it in Java or C++??? – goodvibration Aug 8 at 6:17
0

First of all, saving a function in a variable in solidity is not possible currently. May be you try to use like JavaScript:

var func = function(value){ returns value + 1; }

The next thing is, from the comment section, I saw you used

uint16 requiredYear = getYear(uint dateStampOfMileStone);

You should use if you want to call the function:

uint16 requiredYear = getYear(dateStampOfMileStone);

Hope it will help you.

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.