August 21, 2002 at 4:49 pm
How do I format the result returned by getdate() into mm/dd/yy format?
I've gotten as far as:
PRINT CONVERT(DATETIME,GETDATE(),101)
but that gives me the time as well.
thanks in advance
Billy
August 21, 2002 at 4:52 pm
nevermind...
PRINT CONVERT(varchar(8),GETDATE(),101)
August 21, 2002 at 4:53 pm
quote:
How do I format the result returned by getdate() into mm/dd/yy format?I've gotten as far as:
PRINT CONVERT(DATETIME,GETDATE(),101)
but that gives me the time as well.
thanks in advance
Billy
-------------------------
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
August 21, 2002 at 4:53 pm
Try this out......
-- mm/dd/yy format
select convert(char(8),getdate(),1)
-- mm/dd/yyyy format
select convert(char(10),getdate(),101)
-------------------------
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
August 21, 2002 at 5:05 pm
thanks...
it shows that my previous reply needs to be correct...
PRINT CONVERT(varchar(8),GETDATE(),101)
...does not give you the correct date because the result requires 10 chars, not just 8.
Billy
August 22, 2002 at 3:55 am
Actually you do not have to specify a size on the datatype char or varchar
CONVERT(CHAR,GETDATE(),101) will work just fine.
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
August 22, 2002 at 9:20 am
Antares686 is correct but be aware that if you do not specify a length for varchar or char data types the length will default to 30 bytes, usually not a problem with varchar but may be a problem with char.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply