Ticket T1138349
Visible to All Users

Get LOCAL time from a DateTimeOffset column

created 2 years ago

Hello,

I'm using the Web Report Designer with the ".repx" report format.

In my SQL-Server database, I'm storing dates with UTC "DateTimeOffset" type:

Example :

Clipboard-File-1.png

In the report, I simply want to display a date as Local date.

I tried to use this expression but it doesn't work, as my field is a DateTimeOffset and not a DateTime :

AddHours([MyDateValue],DateDiffHour(UtcNow(), LocalDateTimeNow()))

Is there a solution to simply calculate the local date using a calculated field ? If I want to use this expression, I need to convert the DateTimeOffset to a DateTime…

thank you,

best regards.

Comments (1)

    It seems that this expression show the local date, I don't even know why:

    Code
    FormatString( '{0:dd.MM.yyyy HH:mm:ss}', AddSeconds(AddMinutes(AddHours(GetDate(ToStr( [OperationDate] )),GetHour(ToStr( [OperationDate] )) ) , GetMinute(ToStr( [OperationDate] ))) , GetSecond(ToStr( [OperationDate] ))) )

    Before :

    Clipboard-File-1.png

    After .

    Clipboard-File-2.png

    Is there a better solution ?

    Answers approved by DevExpress Support

    created 2 years ago

    Hello,

    Thank you for contacting us. All Date and Time Functions that are available in our Expression Language are designed for the DateTime data type only. So, it is not possible to use them with the DateTimeOffset data type.

    To accomplish your task, you can create a Custom Function that will accept DateTimeOffset values and convert them to the local time. Check the Custom Function help topic to see how to create custom functions.

    Let me know if this solution works for you.

    It seems that this expression show the local date, I don't even know why:

    The ToStr(Value) function gets the sting representation for the object. For the DateTimeOffset data type, the ToString() method uses formatting information derived from the current culture, so it automatically converts the value to the local time. This is the reason why this works.

      Comments (1)

        Hello,

        Thank you very much for the quick answer.

        I will try with a custom function.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.