Results 1 to 13 of 13
  1. #1
    Md Saim is offline Member
    Join Date
    Sep 2008
    Location
    Kolkata, India
    Posts
    20
    Rep Power
    0

    Post Is there a way to have mySQL auto fill in the current date into my dateCreated field?

    Is there a way to have mySQL auto fill in the current date into my
    dateCreated field?

    In SQLServer I would simply specify the getDate() method as a default value.
    I presume I would use the analogous MySQL function curDate() but it does not
    appear to work for me.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    What does the manual that came with your database say about it?

  3. #3
    Md Saim is offline Member
    Join Date
    Sep 2008
    Location
    Kolkata, India
    Posts
    20
    Rep Power
    0

    Default

    My database manual is MySQL 5.0 Reference Manual.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Okay, and what does it say about possible default values for Date columns?

  5. #5
    Md Saim is offline Member
    Join Date
    Sep 2008
    Location
    Kolkata, India
    Posts
    20
    Rep Power
    0

    Default

    possible default values for Date column is current date.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, there you have it. Continue reading the manual on that page and it will show you how to create the table so it is that way.

  7. #7
    Md Saim is offline Member
    Join Date
    Sep 2008
    Location
    Kolkata, India
    Posts
    20
    Rep Power
    0

    Default

    Hello Mr. masijade......
    At first read my problem. Then reply.

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    So, in other words, you haven't reead the manual and have just been acting like you did.

    Do you know what default values are? When you insert a row without filling a column, and that column has a default value, that default value will be inserted into that column for the row being inserted.

    Now, how does that knowledge, combined with the fact that the manual will tell you how to set up a default value for a column on a table either at table creation or with an alter table command, not answer your question.

    Edit: Ooooooohhhhhhh, I see, you want us to read the manual so you don't have to. That must be it, since I don't see why you would ask a question about database creation/manipulation on a forum dedicated to Java unless that was the case. Hhhhhhhmmmmmm let me see, maybe asking the question the forums available at MySQL :: Developer Zone would have gotten you quicker and more fulfilling answer than this long way around of saying RTFM.
    Last edited by masijade; 09-23-2008 at 01:26 PM.

  9. #9
    Md Saim is offline Member
    Join Date
    Sep 2008
    Location
    Kolkata, India
    Posts
    20
    Rep Power
    0

    Default

    Try to understand my problem Mr. masijade.
    we set a default value for a column on a table.
    But the default value is fixed.
    I want to set the default value is system current date in the date field.

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Read the manual again.

    Edit: In case you still don't get it, make dateCreated a timestamp field or use now() in the insert query. It's not that hard. You can still use getDate() on a timestamp column.
    Last edited by masijade; 09-23-2008 at 02:06 PM.

  11. #11
    dnz
    dnz is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default

    I was googling about this issue when i came across this site. i must say that the response from masijade is quite annoying, that guy is a friggen moron.

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    All information needed was in the manual and easily found. If the individual asking the question were to learn how to read the manual and interpret it's information he would not be dependant on others telling him how to do his work. How is that a bad thing? Are you in the same boat?

  13. #13
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

Similar Threads

  1. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  2. Inserting current date into a DB table
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 08:38 AM
  3. Getting current date using dual (Oracle)
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 02-13-2008, 04:46 PM
  4. how to get the current date and time
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:05 PM
  5. problem with date field
    By Ed in forum JDBC
    Replies: 2
    Last Post: 06-12-2007, 04:27 PM

Posting Permissions

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