I want to fetch only current Date when the contract is created, is there any , method to get Date similar to getTime method.
There is no getDate but you can use getTime and then call toDateUTC to 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
But I want to set a variable āpunchInDateā when contract is created automatically
sample code
controller 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
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 time to let 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 toDateUTC when 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.
--punchInDate = toDateUTC time
This line show me error
parse error on input ā=āparser
Right, you need the let before that as I suggested above
Thatās a great Time/Date tip, thanks @cocreature