« House musing | Main | Ben says: »

July 29, 2008

Slowly I learn

Homework, question 26: Project the current (system) date in a format of your choice (not the default format).

My first attempt:

SELECT
CAST(MONTH(GETDATE()) AS VARCHAR(2))+'/'+
CAST(DAY(GETDATE()) AS VARCHAR(2))+'/'+
CAST(YEAR(GETDATE()) AS VARCHAR(4))
AS Date,
CAST(DATEPART(HOUR,GETDATE()) AS VARCHAR(2))+':'+
CAST(DATEPART(MINUTE,GETDATE()) AS VARCHAR(2))+':'+
CAST(DATEPART(SECOND,GETDATE()) AS VARCHAR(2))
AS 'Proof that this student is up too late' ;


Initial results:

Date Proof that this student is up too late
---------- --------------------------------------
7/29/2008 23:0:20

Final answer:

SELECT
CONVERT(CHAR, GETDATE(), 100) as "Proof that this student is up too late";


Final results:

Proof that this student is up too late
--------------------------------------
Jul 29 2008 11:55PM

Good night!

Posted by Courtney_Sherwood at July 29, 2008 11:57 PM

Comments

These are the kinds of things that I do all day. Date formatting is usually a drag. Oracle has the best functions, but it forces you to use them because its inherent date handling royally sucks.

Posted by: Ben at July 30, 2008 10:33 AM

Post a comment




Remember Me?