Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Date problem

  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    28
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Date problem

    Hi, i am writing an php program that will write the date to MySQL. the table has a date column with type "date". when I insert the data, e.g. "2009-03-24" to the table, the query was sucessful but i got this data "0000-00-00" instead. could anyone helps me what is the problem?? thanks!

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    can you show us your create table statement and your insert statement?

  • #3
    New Coder
    Join Date
    Sep 2004
    Posts
    28
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i create the table by

    create table date_test(
    did, int not null primary key auto_increment,
    dateData, date not null)

    adding data by

    insert into date_test (dateData) values (2009-03-24)

    i am using a wamp 5 as my testing server. i guess something wrong with the MySQL configuration. please give me a hand, thx!!

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    your problem is how you are inserting your date, you need a set of single or double quotes around it. If you don't then it thinks you are doing a mathematical computation (i.e. subtracting 2009 minus 3 minus 24. That would then end up with an incorrect value for a date column. It should give you an error message (it does on mysql 5.0.67), but may change it to 0000-00-00 on an older version of mysql.

  • Users who have thanked guelphdad for this post:

    zawedx (03-26-2009)


  •  

    Posting Permissions

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