Is there any method to get current Date, similar to getTime method
- Muhammad_MoizOP 1
I want to fetch only current Date when the contract is created, is there any , method to get Date similar to getTime method.
- cocreature 2
There is no
getDatebut you can usegetTimeand then calltoDateUTCto get the date of the timestamp. So as an example in a DAML Script, something like this:import DA.Time import DA.Date testScript = do time <- getTime let date = toDateUTC time debug date - Muhammad_Moiz
But I want to set a variable “punchInDate” when contract is created automatically
sample codecontroller createdBy can PunchIn : ContractId Attendance with _associateId : ContractId Associate _communityId : ContractId Community do _punchInTime <- getTime --punchInDate = toDateUTC time create this with communityId = _communityId associateId = _associateId punchInTime = _punchInTime --punchInDate = _punchInDate - cocreature 1
Not sure I’m following. The code you’ve written already seems to do what you are asking for if you include the uncommented code (and change
punchInDate = toDateUTC timetolet punchInDate = toDateUTC time).However, I would recommend against storing both time and date in the contract. If you need the time as well, store that and call
toDateUTCwhen you use it. That way time and date can never get out of sync. If you only need the date, just remove the time field. - Muhammad_Moiz
--punchInDate = toDateUTC time
This line show me error
parse error on input ‘=’parser - cocreature 1
Right, you need the
letbefore that as I suggested above - quidagis 1
cocreature:However, I would recommend against storing both time and date in the contract. If you need the time as well, store that and call
toDateUTCwhen you use it.That’s a great Time/Date tip, thanks @cocreature