SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about Date and NULL

    I'm using phpMyAdmin for a simple mySQL database. Am a bit confused here, as I have two date fields which as far as I can tell are the same - i.e. Date, with a default of NULL, with NULL ticked.

    If I update a record, but leave both of those fields blank, one stays blank, and the other gets populated with 0000-00-00 (and displays 30 November -0001 on the website.)

    Any pointers on why two supposedly identical fields are behaving differently?

    Thanks.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    for starters, those columns aren't identical -- one allows NULL, the other doesn't

    what happens when you "leave both of those fields blank" is this --

    since the NOT NULL column doesn't allow a null, mysql, in its infinite wisdom, instead of rejecting the insert with an error message, decides that it will try to insert a non-null value, and substitutes the "zero" value, which in the case of a DATE column is "0000-00-00" (even though this isn't a valid date by normal standards, mysql allows it)

    not sure how you get 30 November -0001 from 0000-00-00, though
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    for starters, those columns aren't identical -- one allows NULL, the other doesn't

    what happens when you "leave both of those fields blank" is this --

    since the NOT NULL column doesn't allow a null, mysql, in its infinite wisdom, instead of rejecting the insert with an error message, decides that it will try to insert a non-null value, and substitutes the "zero" value, which in the case of a DATE column is "0000-00-00" (even though this isn't a valid date by normal standards, mysql allows it)

    not sure how you get 30 November -0001 from 0000-00-00, though
    They were set up identically in phpMyAdmin, i.e. both set to allow NULL there.

    I have resolved it though - the issue was the syntax in the update script where I had to change a ' ' to a NULL and a LIKE to an =.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •