cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rawatn
Frequent Visitor

Storing datatime to sql database

I have an Edit form on which I have CreationDate field.

I would like to update this field with current datetime and update the database when submitform() is invoked.

 

1 ACCEPTED SOLUTION

Accepted Solutions
eka24
Super User III
Super User III

From your questions:
1. If you submitting the whole form with a button, then:
Put this variable on the Onvisible of the screen:
Set(MyTimeNow,Now())

Then in the default of the datefield datacardvalue put:
If(YourFormName.Mode=FormMode.Edit,MyTimeNow,Parent.Default)

On hiding / disable the field, you can put this formula on the Displaymode of the field If(YourFormName.Mode=FormMode.Edit,View,Edit) . This will prevent them from manually changing the field.

2. But if you are to change on the datefield without submitting the whole form then on the OnSelect of the button put:
Patch('[dbo].[avlist] ',YourTexbox.Text, {DatefieldColumn:Now()})

View solution in original post

3 REPLIES 3
eka24
Super User III
Super User III

Try this
Patch('[dbo].[avlist] ',YourTexbox.Text, {DatefieldColumn:Now()})

Change '[dbo].[avlist] ' to actual sql table
rawatn
Frequent Visitor

Where should I put that syntax?

It will be in datacard update or submit button?

One doubt, can I hide this in the form or say I do not add this field, but in submit button update the current datatime to database?

Is it possible? If yes, How?

eka24
Super User III
Super User III

From your questions:
1. If you submitting the whole form with a button, then:
Put this variable on the Onvisible of the screen:
Set(MyTimeNow,Now())

Then in the default of the datefield datacardvalue put:
If(YourFormName.Mode=FormMode.Edit,MyTimeNow,Parent.Default)

On hiding / disable the field, you can put this formula on the Displaymode of the field If(YourFormName.Mode=FormMode.Edit,View,Edit) . This will prevent them from manually changing the field.

2. But if you are to change on the datefield without submitting the whole form then on the OnSelect of the button put:
Patch('[dbo].[avlist] ',YourTexbox.Text, {DatefieldColumn:Now()})

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (81,576)