Click to See Complete Forum and Search --> : T-SQL


jwright4
June 20th, 2001, 03:54 PM
I am trying to trim or truncate a Date within my SQL 7 database to get rid of the Timestamp associated with it. The current format is - mm/dd/yyyy hh:mm:ss
I want it to look like - mm/dd/yyyy

Any suggestions?

Cakkie
June 21st, 2001, 12:58 AM
If you mean in the database itself, that isn't possible, cause their is no difference between date and time, it's all datetime. If you really want to get rid of it, you can convert it to a string, but then you lose all the advantages of the date data type. Or you can do both, just create a computed column that holds the value as a string in a given format.
If you just need to format it (like say for a report or query), there are several functions available. I think in this case you should use the convert function, which allows you to temporary convert it to a varchar with a given format (you should check out the SQL books online for more information on this function.)

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

Clearcode
June 21st, 2001, 03:30 AM
The Convert keyword in SQL server/Sybase can be used e.g.


Select Convert(VarChar(8),Timestamp,112) From TUSERS
--Timestamp is of datatypoe DATETIME





HTH,
D.

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com

Iouri
June 21st, 2001, 07:14 AM
If you are using this string in VB thenb you can format the string

Format(MyDate,"mm/dd/yyyy")

Iouri Boutchkine
iouri@hotsheet.com