Skip to main content
Inspiring
March 18, 2008
Question

SQL Server 2000 database GETDATE() default for field

  • March 18, 2008
  • 8 replies
  • 1615 views
I have a SQL Server 2000 database where the createDate field has a default value of GETDATE() and the data type is datetime. It is inserting the date just fine, but I do not want to capture the time along with the date. I only want the date to be entered. How can I accomplish this? Thanks!
This topic has been closed for replies.

8 replies

Inspiring
March 18, 2008
If you make it the default, you don't have to enter anything.
Inspiring
March 18, 2008
IF you only wanted to store the date, then yes you would use that as the column default value.

...
createDate datetime default convert(datetime, convert(varchar, getDate(), 102), 102)

However, as paross1 cautioned be sure you understand you will only be capturing the date from now on. If you change your mind later, and decide you need both the created date and time, you will be seriously out of luck. A safer choice might be to keep the date and time, and use convert in your queries instead.


ssailerAuthor
Inspiring
March 18, 2008
would you enter this directly into the default value for the field?

convert(datetime, convert(varchar, getDate(), 102), 102)
Inspiring
March 18, 2008
Added to paross1's comments, I would suggest using a less ambiguous date format and/or a double convert. To guarantee the date string is converted properly.

convert(datetime, convert(varchar, getDate(), 102), 102)
ssailerAuthor
Inspiring
March 18, 2008
never mind - I put it directly into the default value of the field and it's working. This has been a problem for days - thank you!
Participating Frequently
March 18, 2008
Don't forget, since your column is still type datetime, a "date" stripped of its time component is essentially midnight (time 00:00:00, etc.)

Phil
Inspiring
March 18, 2008
It could be done in a query or in the column "default" statement. The choice is yours.
ssailerAuthor
Inspiring
March 18, 2008
CAST(CONVERT(VARCHAR, GETDATE(), 101) AS datetime)

This would be done in an underlying view or query, right?
Inspiring
March 18, 2008
Use the convert function to truncate the time from getdate()
Participating Frequently
March 18, 2008
Something along the lines of this.....

CAST(CONVERT(VARCHAR, GETDATE(), 101) AS datetime)

Phil