Skip to content

bug: date_add with now should return right value #16711

@TCeason

Description

@TCeason

Search before asking

  • I had searched in the issues and found no similar issues.

Version

main

What's Wrong?

If now() at 2024-10-28 19:43:00 Asia/Shanghai, date_add(year, 1, now()) will return unexpect value.

How to Reproduce?

set timezone='Asia/Shanghai';

:) select date_add('year', 1, now()); --BUG

SELECT DATE_ADD(YEAR, INTERVAL 1, now())

┌────────────────────────────┐
│  DATE_ADD(YEAR, 1, now())  │
│          Timestamp         │
├────────────────────────────┤
│ 2025-10-29 03:50:02.806422 │
└────────────────────────────┘
1 row read in 0.025 sec. Processed 1 row, 1B (39.59 rows/s, 39B/s)


:) select date_add('year', 1, '2024-10-28 19:49:52.684937')::TIMESTAMP; -- normal

SELECT DATE_ADD(YEAR, INTERVAL 1, '2024-10-28 19:49:52.684937')::TIMESTAMP

┌────────────────────────────────────────────────────────────┐
│ DATE_ADD(YEAR, 1, '2024-10-28 19:49:52.684937')::TIMESTAMP │
│                          Timestamp                         │
├────────────────────────────────────────────────────────────┤
│ 2025-10-28 00:00:00                                        │
└────────────────────────────────────────────────────────────┘
1 row read in 0.061 sec. Processed 1 row, 1B (16.37 rows/s, 16B/s)

tmp resolve

:) select now(), to_timestamp(add_years(today(),1))+(current_timestamp() - today());

SELECT
    now(),
    (to_timestamp(add_years(today(), 1)) + (current_timestamp() - today()))

┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
│            now()           │ to_timestamp(add_years(today(), 1)) + (current_timestamp() - today()) │
│          TimestampTimestamp                               │
├────────────────────────────┼───────────────────────────────────────────────────────────────────────┤
│ 2024-10-28 19:59:39.7223312025-10-28 19:59:39.722331                                            │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

Labels

C-bugCategory: something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions