[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 594
  • Last Modified:

Current Date on record creation

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?

Thanks!
0
edvinson
Asked:
edvinson
  • 2
1 Solution
 
johanntagleCommented:
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.
0
 
edvinsonAuthor Commented:
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?
0
 
johanntagleCommented:
not knowing the actual statement and error message, I cannot suggest anything further.
0
 
DcpKingCommented:
Please post your insert statement: I would have expected it to be something like
insert into TableName
(field1, field2, created_date)
values
(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).

hth

Mike
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now