Current Date on record creation

Posted on 2012-08-24
Last Modified: 2012-10-10
I am having a hard time getting this simple task to work:

1. I have a field, created_date , Type: datetime

2. I want today's date inserted when a record is created.

I have tried NOW() , CURDATE, etc.

Nothing is working.

Any suggestions?

Question by:edvinson
    LVL 24

    Expert Comment

    either one should work.  Can you post your insert statement?  Also post what happens after you run it, e.g. error message, actual resulting row that was inserted.
    LVL 1

    Author Comment

    I am actually getting the error INSIDE of my Database Mgmt software, called Navicat.

    I suppose I will use the CMD line to alter the table, and see if that works. Is that what you would suggest?
    LVL 24

    Expert Comment

    not knowing the actual statement and error message, I cannot suggest anything further.
    LVL 16

    Accepted Solution

    Please post your insert statement: I would have expected it to be something like
    insert into TableName
    (field1, field2, created_date)
    (val1, val2, curdate());

    Open in new window

    OTOH, try specifying CurDate() as the default value for the field. Then when you insert a new record, you can just omit the field entirely and the date will be inserted in automatically (same as above - just don't mention the last field in either the field list or the value list).



    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now