How do you get the current Date in Daml?

Hi @amiracam, take a look at a related question on this.

Basically it boils down to using getTimeand extracting the date from taht new Date () is Java syntax and not valid Daml. You also cannot do this at the top-level, so you have to move it in the do-block. Putting things together, your example could be something like this:

repo_test_1 =
  scenario do
    jpm <- getParty "JPM"
    fed <- getParty " FED"
    nowTime <- getTime
    let nowDate = toDateUTC nowTime
    submit jpm do
      create Repo with
        owner = jpm
        regulator = fed
        par = 1.5
        cusip = "9999999"
        trateDate = nowDate

Lastly, I recommend to use Daml Script instead of scenarios for all new projects. Your example translates to Daml Script with minimal changes:

repo_test_1 =
  script do
    jpm <- allocateParty "JPM"
    fed <- allocateParty " FED"
    nowTime <- getTime
    let nowDate = toDateUTC nowTime
    submit jpm do
      createCmd Repo with
        owner = jpm
        regulator = fed
        par = 1.5
        cusip = "9999999"
        trateDate = nowDate
2 Likes