4.3 admin date format

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 years ago
HI is any got the solution ,
like need to change the DD/MM/YYYY

as I have follow this things and change the the culture language as suggest by AM , but still not work
I prefer this link but not work for me

can any one have idea regarding about this that without changes the code in framework  file
let me know if have any idea regarding the date format
2 years ago
i think there is no easy option here, NOP don't seem interested in fixing something so basic.

this is one of the (numberous) reasons we've moved away from NOP now - good luck
2 years ago
Here is an easy option :)
I use Kendo for my date fields in Plugins
It is pretty simple you dont need to change any code to use it
I just threw this together for instance on the Order/List.cshtml to change the StartDate entry

Change/Add this code at the top

@model OrderSearchModel

@inject IStoreService storeService
@using Nop.Services.Stores
@using System.Globalization

@{
    //page title
    ViewBag.PageTitle = T("Admin.Orders").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Orders");

    const string hideSearchBlockAttributeName = "OrdersPage.HideSearchBlock";
    var hideSearchBlock = genericAttributeService.GetAttribute<bool>(workContext.CurrentCustomer, hideSearchBlockAttributeName);

    var language = workContext.WorkingLanguage;
    string shortDatePattern = CultureInfo.GetCultureInfo(language.LanguageCulture).DateTimeFormat.ShortDatePattern;
    string toDisplayFormat = "dd/MM/yyyy"; // Default pattern

    if (shortDatePattern.Contains("M/d/") || shortDatePattern.Contains("MM/dd/") ||
        shortDatePattern.Contains("M.d.") || shortDatePattern.Contains("MM.dd."))
    {
        //US or others cultures pattern
        toDisplayFormat = "MM/dd/yyyy";
    }

    string kendoToStringFormat = toDisplayFormat;
}

Change the Field  code
<div class="form-group row">
    <div class="col-md-4">
        <nop-label asp-for="StartDate" />
    </div>
    <div class="col-md-8">
        <input type="text" name="@Model.StartDate" id="StartDate" />
    </div>
</div>

Add some script to activate the field
<script>
    $(document).ready(function () {
        $("#StartDate").kendoDatePicker({
            format: "@kendoToStringFormat"
        });
    });
</script>
2 years ago
@Yidna
Thank for response

Yes you are right but this for only order list ,
I needed in full nop ,
tried the other things as suggest by AM in language culture , but not getting luck for that
if any thing apart this if have then please inform
2 years ago
I see that now all Views have this RenderDate class implemented when there is some Date that should be displayed.
https://github.com/nopSolutions/nopCommerce/blob/develop/src/Presentation/Nop.Web.Framework/Models/DataTables/RenderDate.cs

So one way is to supply Format property in new RenderDate instance, ex. in _LatestOrders.cshtml (Areas/Admin/Views/Home):


new ColumnProperty(nameof(OrderModel.CreatedOn))
                {
                    Title = T("Admin.Orders.Fields.CreatedOn").Text,
                    Width = "100",
                    Render = new RenderDate() { Format = "DD-MM-YYYY HH:mm:ss" }
                },


But again I don't see why is this not some global setting, so you don't have to set it manually on all Views, or I am missing something?
2 years ago
The DEFAULT_DATE_FORMAT in RenderDate has to be a moment.js format. Kendo DateTime picker is using the current language Culture and since the grid in nopCommerce is no longer using Kendo Grid, nopCommerce introduced a RenderDate class but never attempt to make it consistent with Kendo UI. The code below will return the format used by the current language Culture thus achieving consistency. All you need to do is changing the language Culture and the Date Time format everywhere will be reflected as well. This of course requires re-compilation and re-deployment.

private string DEFAULT_DATE_FORMAT = GenerateMomentJsFormatString("g");


The method GenerateMomentJsFormatString is taken from https://stackoverflow.com/a/41653618. It is too long to be included here.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.