Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-36093

cast(now()+X) doesn't wrap into the next hour

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.11, 12.0(EOL)
    • N/A
    • Temporal Types
    • None

    Description

      We can add ints to the result of now() and cast the sums back to datetime types:

      MariaDB [test]> select now(), cast(now()+4200 as datetime);
      +---------------------+------------------------------+
      | now()               | cast(now()+4200 as datetime) |
      +---------------------+------------------------------+
      | 2025-02-14 15:12:32 | 2025-02-14 15:54:32          |
      +---------------------+------------------------------+
      1 row in set (0.001 sec)
      

      As seen above, we add 4200 to now() and we get a time 42 minutes later.

      However, if we add a large enough value such that the result would cross into the next hour, as seen below, we get a NULL when casting instead:

      MariaDB [test]> select cast(now()+5200 as datetime);
      +------------------------------+
      | cast(now()+5200 as datetime) |
      +------------------------------+
      | NULL                         |
      +------------------------------+
      1 row in set, 1 warning (0.001 sec)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Gosselin Dave Gosselin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.