Skip to content

Date field: string vs. Date types #10605

Open

Description

@cbratschi

Describe the Bug

The date field stores its value as Date binary data in BSON (MongoDB). The validation function defines the value as Date too:

https://github.com/payloadcms/payload/blob/main/packages/payload/src/fields/validations.ts#L374

However, the type of value is string in reality. And code like this contains a workaround:

https://github.com/payloadcms/payload/blob/main/packages/payload/src/fields/validations.ts#L377

Strangely, it first converts the value to string and then parses its value. The Payload generated types use string for dates. In order to be compliant the Date type should be changed to string in the validation function definition.

For future releases it would be better to use Date values.

Link to the code that reproduces this issue

https://github.com/cbratschi/payload

Reproduction Steps

See above.

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
  Node: 22.12.0
  npm: 10.9.0
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  payload: 3.13.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:23 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Jan 15, 2025
  2. removed
    validate-reproduction
    on Jan 15, 2025
  3. paulpopus commented on Feb 6, 2025

    @paulpopus
    Member

    I think for now on our side we think dates should remain as strings instead of them being cast to Date. When returned via the REST API for example it would always return a string regardless.

    I also think that as a UTC string it's gonna be easier for people to handle any conversions as needed since Date is always localised to the system/user locale.

  4. removed
    status: needs-triage
    on Feb 6, 2025
  5. cbratschi commented on Feb 6, 2025

    @cbratschi
    ContributorAuthor

    @paulpopus Please reopen, I am fine with the string as type but Payload defines the type currently as Date and not string. This is the confusion.

  6. paulpopus commented on Feb 6, 2025

    @paulpopus
    Member

    Ohh I see, re-opening then so we can revisit and confirm our types

  7. added
    status: needs-triage
    on Feb 6, 2025
  8. JessRynkar commented on Jan 19, 2026

    @JessRynkar
    Member

    Hi! Are you still experiencing this on the latest version v3.72.0? Some work improvements were made to date fields last year.

  9. JessRynkar commented on Feb 2, 2026

    @JessRynkar
    Member

    Since we haven’t heard back in a while and this issue relates to several releases ago, we’re going to close it for now. If you’re still seeing this behavior on the latest version, please open a new issue with updated reproduction steps and environment details so we can investigate.

  10. removed
    status: needs-triage
    on Feb 2, 2026
  11. self-assigned this
    on Feb 3, 2026
  12. added
    status: needs-triage
    on Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugPayload OSSengagement: mediumstatus: needs-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions