Inserting NOW() value in datetime datatype is returning 0000-00-00 00:00:00

后端 未结 3 1167
攒了一身酷
攒了一身酷 2021-01-26 10:13

I had a database that had a perfectly working NOW() function, displaying the right date. And after accidentally deleted it, I created a similar database, but when I inserted NOW

相关标签:
3条回答
  • 2021-01-26 10:47

    You have quotes around the NOW() function. Change it to:

    INSERT INTO `blog_details` (`title`, `blog_content`, `blog_date`, `cat_name`)
    VALUES('Breaking Bad TV Series', 'Best series evar', NOW(), 'Uncategorized');
    
    0 讨论(0)
  • 2021-01-26 10:48

    What you're inserting is the string "NOW()" which is completely different from the function call NOW().

    As "NOW()" is not a valid date, it goes in as zero.

    Removing the quotes from that should fix the issue.

    0 讨论(0)
  • 2021-01-26 11:05

    You shouldn't have to quote the NOW() function, so try without the ' ' and see if that helps.

    INSERT INTO blog_details(title, blog_content, blog_date, cat_name)
    VALUES('Breaking Bad TV Series', 'Best series evar', NOW(), 'Uncategorized');
    
    0 讨论(0)
提交回复
热议问题