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

when passing datetime value to service , it saved as one day prior in Database. how t o resolve this issue? #6675


User avatar
0
kalidarscope created

suppose, I select 03-21-2019 it saved as 03-20-2019.

This is the code I am using to save in Typescript.

    input.creatioN_TIME = moment(this.CreateDate);
    input.expirY_DATE = moment(this.ExpiryDate);
    
      this._organizationService.createOrUpdateASAPOrganizationsHub(input)
        .pipe(finalize(() => this.saving = false))
        .subscribe(() => {
            this.notify.info(this.l('SavedSuccessfully'));
            this.OrganizationSave.emit(this.organization);
            this._router.navigate(['app/admin/ASAPOrganizationHub']);
        });

5 Answer(s)
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, it is probably due to non-utc datetime to utc conversion.

    ifClockProviders.Utc is used, the client side date time will be converted in utc before sending to the server.

    See https://aspnetboilerplate.com/Pages/Documents/Timing.

  • User Avatar
    0
    kalidarscope created

    would you send me format

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    • Have you set ClockProviders.Utc to UtcClockProvider ?
    • Could you send the date send to server from client ? You can check it in the network tab of Google Chrome for your request.
  • User Avatar
    0
    maharatha created

    I am having the same problem, And I have set Clock.Provider = ClockProviders.Utc; Now I am storing dates which I don't want to be converted and store the data as it is.

    In order to do that what I need to do so that it deosn't convert and store the data as it is.

  • User Avatar
    0
    rucksackdigital created

    I ran into a similar problem using UTC as my clockProvider on the server side. The resolution I found was, before submitting from client side to server side for processing, you need to specify the format of the datetime object.

    Below is jQuery but gives you the idea:

    $('.datetime-picker').datetimepicker({
                    minDate: new Date(),
                    locale: abp.localization.currentLanguage.name,
                    format: 'L LT'
                });
    

    to render you Datetime field selector to your end user. Before posting to server:

    var formattedDate = $("#Notification_AutoBroadcastDate").data("DateTimePicker").date().format("YYYY-MM-DDTHH:mmZ");
    

    and return formattedDate to your server for processing, which will include the timezone offset.

    If you do not include the timezone offset when submitting to server, it is assumed to be a UTC date.