Set value to a date time variable on saving a date field

Hi All,
I have a scenario where there is a date field and once a date is entered, a date and time field should replace a date field with a defaulted time and the date.
If I remove either date or time in the date time field, it should again go back to a empty date field. Following is the code

load(
local!dt1,
local!dtTm1,
if(isnull(local!dt1),
a!dateField(
label:"date",
value:todate(local!dt1),
saveInto:{local!dt1,a!save(local!dtTm1,gmt(todatetime(save!value & " " & "16:00")))}
),
a!dateTimeField(
label:"dateTime",
value:todatetime(local!dtTm1),
saveInto:{local!dtTm1,local!dt1}
)
)



)




But when I again enter a date in the date field, the date and time field populates with a previously entered date and time instead of current chosen one. Is there any other way to implement this?

Thanks in advance.

OriginalPostID-251525

  Discussion posts and replies are publicly visible

Parents
  • It is caused by adding the hours - in the first instance, you are selecting a date from a date field which has no time component. In the second part where you are saving this value, it cannot be cast and throws the error:
    "Could not cast from Time to Date and Time with Timezone."

    For this to work, the first date should also be datetime, not just time, but with the hours set to 00:00 and include the timezone too.
Reply
  • It is caused by adding the hours - in the first instance, you are selecting a date from a date field which has no time component. In the second part where you are saving this value, it cannot be cast and throws the error:
    "Could not cast from Time to Date and Time with Timezone."

    For this to work, the first date should also be datetime, not just time, but with the hours set to 00:00 and include the timezone too.
Children
No Data