drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Option for ISO 8601 String Format in timestamp({ mode: 'string' })
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
Here's an improved version of your feature request with clearer structure, more precise wording, and a stronger rationale:
---
### Feature Request: Option for ISO 8601 String Format in `timestamp({ mode: 'string' })`
#### **Background**
In Drizzle ORM, timestamps can be returned as strings when using `mode: 'string'`. However, the default format is `YYYY-MM-DD HH:MM:SS.ssssss`, which is not in ISO 8601 format.
For example:
```ts
{
id: 1,
timestamp1: 2024-04-11T14:14:28.038Z, // Date object
timestamp2: '2024-04-11 14:14:28.038697' // string
}
```
This leads to a common pain point where developers frequently need to convert the string format manually:
```ts
new Date(timestamp).toISOString();
```
As an application scales, this becomes repetitive and error-prone.
#### **Feature Request**
Introduce an option to automatically return timestamps in ISO 8601 format when using `mode: 'string'`.
For example:
```ts
timestamp('timestamp2', { mode: 'string', format: 'ISO 8601' });
```
This would return:
```ts
{
id: 1,
timestamp2: '2024-04-11T14:14:28.038Z' // Automatically formatted
}
```
#### **Benefits**
- Eliminates the need for repeated `new Date(timestamp).toISOString()` conversions.
- Improves consistency in API responses when mixing `mode: 'date'` and `mode: 'string'`.
- Provides a more standardized timestamp format that aligns with common frontend and API expectations.
#### **Alternative Approaches**
- A global setting to enforce ISO 8601 formatting for all string timestamps.
- A utility function built into Drizzle to facilitate conversion.
Would love to hear your thoughts on this!
---
This version maintains your original intent while improving clarity, structure, and persuasion.
Related: https://github.com/drizzle-team/drizzle-orm/issues/1757
Contributor guide
Assessment
This issue has not been assessed yet.