Is there any method to get current Date, similar to getTime method

I want to fetch only current Date when the contract is created, is there any , method to get Date similar to getTime method.

1 Like

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
2 Likes

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.

1 Like

--punchInDate = toDateUTC time
This line show me error
parse error on input ‘=’parser

Right, you need the let before that as I suggested above

1 Like

A post was split to a new topic: Access to time during contract creation

That’s a great Time/Date tip, thanks @cocreature

1 Like

A post was split to a new topic: Type mismatch error