Why do I have problems inserting NOW() into a database?
Several hiccups can happen when trying to INSERT or UPDATE a record with the current date and time. For one, regional settings and/or SQL Server's dateformat setting can throw you for a loop (see Article #2260 for some workarounds to regional settings issues), and even delimiters can get in the way when moving between platforms (see Article #2023).
My suggestion: let the database put the date and time on the record. In SQL Server, you can do this:
(And for UPDATEs, you could create a trigger.)
This way, you don't have to worry about your application code getting the date format correct (since SQL Server will automatically generate the current time for you, and store it in its own internal format), and you can have one less column in your INSERT list.
Related ArticlesCan I get millisecond accuracy in ASP?
Can I make VBScript format dates for me?
Could I get a little help with dates?
Given a date, how do I find the beginning and end of that week?
Given two dates, how do I determine an age?
How do I calculate dates, such as the first day of the month?
How do I convert a DATEDIFF to days, hours, and minutes?
How do I convert a timespan, in seconds, to HH:MM:SS?
How do I convert local time to UTC (GMT) time?
How do I count the number of business days between two dates?
How do I delimit/format dates for database entry?
How do I determine the number of seconds since 1/1/1970?
How do I display time in military format?
How do I implement a calendar / datepicker in ASP?
How do I select time only from a DATETIME column?