Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Mismatch in Dates #5450


User avatar
0
bilalhaidar created

Hi, I have a calendar control to receive the Date of Birth of the person. The application zone is set to Beirut which is +2 GMT. On the server, I am using Utc Provider.

So, let's say the user selects his birthday as 4/11/2000, since I am using PrimeNG date picker, I see the date stored in the DB as 3/11/2000 21:00:00. (In summer, we are +3 GMT)

Next time, I want to edit the record, also, the Date of Birth shows as 4/11/2000.

Now, when I want to export the data to Excel, because I had the need to use PIVOTs in TSQL, so I am using a DataTable to read the data from the SQL (calling a Stored Procedure).

When I export the data, I see the Date of Birth field as 3/11/2000

Here is the code I am using to parse and format date in Excel:

case "System.DateTime":
    var dateTime = (DateTime?)pocDataTable.Rows[r][columnName];
    DateTime? tempDateTime = null;
    if (dateTime.HasValue)
    {
        tempDateTime = Clock.Normalize(dateTime.Value);
     }
     value = _timeZoneConverter.Convert(tempDateTime);
     break;

4 Answer(s)
  • User Avatar
    0
    bilalhaidar created

    Okay, I have an update!

    The date 3/11/2000 21:00:00 is indeed a UTC date representation of 4/11/2000 00:00:00+3 that I receive from the client.

    When the client renders the value it is being rendered correct as 4/11/2000.

    Now, when exporting to Excel:

    tempDateTime = Clock.Normalize(dateTime.Value);
    

    tempDateTime is just the date stored in the Database in UTC format.

    This line below, is keeping the date in UTC format, hence the reason I am getting this weird behavior:

    value = _timeZoneConverter.Convert(tempDateTime);
    

    Why the _timeZoneConverter is not picking up the Timezone set in the application and convertnig the date to it accordingly?

    Thanks

  • User Avatar
    0
    aaron created
    Support Team

    Did you set the application timezone?

  • User Avatar
    0
    bilalhaidar created

    Yes, I set it to my timezone which is Beirut. How can I check the value of the timezone being set while running the app?

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi @bilalhaidar, you can read the application timezone using the following

    // using Abp.Configuration
    // using Abp.Timing.Timezone
    
    var applicationsTimezone = _settingManager.GetSettingValueForApplication(TimingSettingNames.TimeZone);
    value = _timeZoneConverter.Convert(tempDateTime);