all groups > sql server programming > february 2005 >
You're in the

sql server programming

group:

Help with Default Value


Help with Default Value Neil Steventon
2/19/2005 5:57:47 PM
sql server programming:
Hi,

I have a table with a filed called - DateEntered which has the default value
of getdate().
I woul however just like it to return the date in the format dd/mm/yyyy
without the time, how do you do this as a default value.

I ca query the table and convert but thought there must be a simple way to
do this , anybody know?

Thanks

Neil

Re: Help with Default Value MGFoster
2/19/2005 6:44:23 PM
[quoted text, click to view]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The result of the call to GETDATE() will be both the date & the time.
If you just want the date value to be stored you can use the CONVERT()
function like this:

... DEFAULT CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(),101))

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQheJDYechKqOuFEgEQJhNwCfaGmZJA+vVzJOUoUoDVTTKkqFQ4kAoLtG
j6bebg4dk1iETa+msZ2o5Tsg
=KnG6
Re: Help with Default Value Neil Steventon
2/20/2005 2:32:23 AM
Thank you ,

That works great just what I wanted - I didnt think you could do it like
this. I thought because it was a date field then I couldnt convert it in
the default value to a varchar.

Cheers for the help.

Neil


*** Sent via Developersdex http://www.developersdex.com ***
Re: Help with Default Value Uri Dimant
2/20/2005 12:36:06 PM
Or
If you don't want to see a time at all
select CONVERT(CHAR(10), GETDATE(),101)





[quoted text, click to view]

Re: Help with Default Value Hugo Kornelis
2/21/2005 2:07:46 PM
[quoted text, click to view]

Hi Neil,

You can - SQL Server will implicitly convert the varchar value back to
datetime in order to store it in the column, but the time part is gone by
then.

Another way to do it, using only date functions (and slightly quicker,
ythough you'll probably never notice) is

DATEADD(day, DATEDIFF(day, '20040101', GETDATE()), '20040101')

Best, Hugo
--

AddThis Social Bookmark Button