1

I'm trying to make a get function based on date(in timestamp) Do I need another mapping? Take into consideration that it might be more than one registries on the same date. Any help is great. :)

   struct Route{
        uint id;
        uint date;
        string driverName;
        string routeBinId;
    }
    mapping(uint256 => Route) routes;
    
    // Set/Store Data
    function setRouteData( uint256 _date, string memory _driverName, string memory _routeBinId)
    public _ownerOnly payable {
        routes[routeId] = Route(routeId, _date, _driverName, _routeBinId);
        routeId++;
    }
    // Get All Data
    function getRouteData() external view _ownerOnly returns (Route[] memory){
      Route[] memory id = new Route[](routeId);
      for (uint i = 0; i < routeId; i++) {
          Route storage route1 = routes[i];
          id[i] = route1;
      }
      return id;
    }
    // Get Data based on Id
    function getRouteDataBasedOnId(uint _routeId) external view _ownerOnly returns(Route memory){
        return routes[_routeId];
    }
}

1 Answer 1

0

Hope this article will help you resolve it. https://soliditytips.com/articles/solidity-dates-time-operations/

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.