Hi, I have a problem with my date value. I patch the date requested (in text label) from canvas apps back to cds. However, the date become one day less than the one requested from canvas apps. why is that?
Because it could depend on the behavior of the date field in CDS
You can check here:
Date and time field behavior and format
The following table contains information about the date and time field behavior and format.
|User Local||Date Only|
- or -
Date and Time
|This is the default behavior of custom date and time fields.|
The field values are displayed in the current user’s local time.
In Web services, these values are returned using a common UTC time zone format.
You can change this one time if you select the default behavior. More information Change User Local Behavior
|Date Only||Date Only||No Time zone conversion.|
The time portion of the value is always 12:00AM.
The date portion of the value is stored and retrieved as specified in the UI and Web services.
|Time-Zone Independent||Date Only|
- or -
Date and Time
|No Time zone conversion.|
The date and time values are stored and retrieved as specified in the UI and Web services.
But why is that when I patch the date based on the editform of the entity,the date value stays the same in the cds and the canvas apps?
This could potentially be because there may be a difference in how the date is interpreted when patching from Text and patching from Date control. if the CDS is also a Date control (we are presuming it is - is this true?) and you patched from a Text label, we think you may be getting results that are not consistent.
You could try following :
But I have a condition for the date requested, which is the user can choose the default days (how many days) for shipping. That's why I use the text field. The date I'm patching back to cds is = datevalue + default days
You could also try just adding the Date to the number of days instead of using a Text Label.
DateAdd( YourDateTimeFromDatePicker, Value(NumberOfDaysFromOtherField.Text) )
Reason you do Value(NumberOfDaysFromOtherField.Text) for the second argument is because if you are using DateAdd and the second argument has to be a number - Value(NumberOfDaysFromOtherField.Text) converts Text to Number. If the other control reference is already a number, then you may not need to wrap Value function around it and possibly can use it directly. If the number is in an input field then it may need to have Value wrapped around it like above example.
The above example DateAdd returns a new Date/Time value with the number of days added. Then you would patch this instead of the text value, in order to patch a Date without needing to patch a Text value. So you can use that entire DateAdd statement above (and change it slightly for your case) instead of having to use a Text label to store the date.
Try playing with the UTC conversion to and from of the date in PowerApps Canvas App, right before patching it, and see if you can get the dates to align if you send it as a current UTC date and time, etc.:
Converting to UTC
To convert to UTC (Coordinated Universal Time), add the TimeZoneOffset for the given time.
For example, imagine the current date and time is July 15, 2013, 1:02 PM in Pacific Daylight Time (PDT, UTC-7). To determine the current time in UTC, use:
TimeZoneOffset defaults to the current time, so you don't need to pass it an argument.
To see the result, use the Text function with the format dd-mm-yyyy hh:mm, which will return 15-07-2013 20:02.
Converting from UTC
To convert from UTC, subtract the TimeZoneOffset (by adding the negative) for the given time.
For example, imagine the UTC date and time July 15, 2013, 8:02 PM is stored in a variable named StartTime. To adjust the time for the user's time zone, use:
Note the negative sign before TimeZoneOffset to subtract the offset rather than add it.
To see the result, use the Text function with the format dd-mm-yyyy hh:mm, which will result in 15-07-2013 13:02 if you're in Pacific Daylight Time.
Could you share the Date field setting and formulas generated the date?
This seems to be a Timezone issue, but I cannot reproduce the issue.
Hope you can share more information
this is the formula I use to generate my date.
Learn how to create your own user groups today!
Check out the new Power Platform Community Connections gallery!
Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.