Open Closed

DateTime validation not accepting valid DateTime string #7657


User avatar
0
Chris.Didonna created

ABP Framework version: v5.3.0

UI Type: Angular

Database System: EF Core (PostgreSQL.)

Tiered (for MVC) or Auth Server Separated (for Angular): no

When I try to set a datetime string in Angular that is a valid format to a datetime field in a DTO I get a validation exception in Angular.

Even when I try a different format:

I can't find anything in the Validation documentation that addresses this automatic datatype validation. We haven't set any special rules for validation of this field or defined a specific format for it.

It WILL accept an ordinary date string without the time like this: "13/04/2024".

How do I get it to accept a value that includes time?

The DTO:

export interface GetRunListDto extends PagedAndSortedResultRequestDto {
  filterText?: string;
  name?: string;
  startDateTimeMin?: string;
  startDateTimeMax?: string;
  scenarioName?: string;
}

 "eWater.Repros.Runs.GetRunListDto": {
      "baseType": "Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto",
      "isEnum": false,
      "enumNames": null,
      "enumValues": null,
      "genericArguments": null,
      "properties": [
        {
          "name": "FilterText",
          "jsonName": null,
          "type": "System.String",
          "typeSimple": "string",
          "isRequired": false
        },
        {
          "name": "Name",
          "jsonName": null,
          "type": "System.String",
          "typeSimple": "string",
          "isRequired": false
        },
        {
          "name": "StartDateTimeMin",
          "jsonName": null,
          "type": "System.DateTime?",
          "typeSimple": "string?",
          "isRequired": false
        },
        {
          "name": "StartDateTimeMax",
          "jsonName": null,
          "type": "System.DateTime?",
          "typeSimple": "string?",
          "isRequired": false
        },
        {
          "name": "ScenarioId",
          "jsonName": null,
          "type": "System.Guid?",
          "typeSimple": "string?",
          "isRequired": false
        }
      ]
    }
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

9 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    HI,

    here is the DateTimeModelBinder to convert string to datetime.

    https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/Binders/DateTimeModelBinder.cs#L35

    You can see the supported time format in swagger

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Chris.Didonna created

    We aren't using MVC we are using Angular front end. Is this something I have to define on the DTO on the server side?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    The error message comes from server

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Chris.Didonna created

    We don't use MVC so can DateTimeModelBinder still be used?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    Yes, the server-side uses it.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Chris.Didonna created

    Well I added the MVC modules but there's nothing on how I'm supposed to make this class work.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    I mean your time format is not correct.

    This is the code logic for binding time https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ModelBinding/Binders/DateTimeModelBinder.cs#L35

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Chris.Didonna created

    Ok I see now. I'll try to get that format In Angular.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    okay,

    if you get any else problem please let me know

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.