0
SQL Server 2000 database GETDATE() default for field
Participant
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/td-p/398480
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
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!
TOPICS
Advanced techniques
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398481#M35880
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
Use the convert function to truncate the time from
getdate()
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mentor
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398482#M35881
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
Something along the lines of this.....
CAST(CONVERT(VARCHAR, GETDATE(), 101) AS datetime)
Phil
CAST(CONVERT(VARCHAR, GETDATE(), 101) AS datetime)
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ssailer
AUTHOR
Participant
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398483#M35882
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
CAST(CONVERT(VARCHAR, GETDATE(), 101) AS datetime)
This would be done in an underlying view or query, right?
This would be done in an underlying view or query, right?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398484#M35883
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
It could be done in a query or in the column "default"
statement. The choice is yours.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ssailer
AUTHOR
Participant
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398485#M35884
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
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!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mentor
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398486#M35885
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
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
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398487#M35886
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
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)
convert(datetime, convert(varchar, getDate(), 102), 102)
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ssailer
AUTHOR
Participant
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398488#M35887
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
would you enter this directly into the default value for the
field?
convert(datetime, convert(varchar, getDate(), 102), 102)
convert(datetime, convert(varchar, getDate(), 102), 102)
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398489#M35888
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
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.
...
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/sql-server-2000-database-getdate-default-for-field/m-p/398490#M35889
Mar 18, 2008
Mar 18, 2008
Copy link to clipboard
Copied
If you make it the default, you don't have to enter
anything.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

