Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert datetime to MM/DD/YY HH:MM AM/PM

Author  Topic 

chiman

21 Posts

Posted - 2008-04-07 : 10:55:45
Hi,
Is there a way to convert the date time column to MM/DD/YY HH:MM AM/PM format.
I tried
Select Convert(varchar , Getdate(),100). But this is not in MM-DD-YY format..

Thanks in advance..

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-04-07 : 11:15:52
No doubt there are better ways, but here's one way...

select
replace(convert(varchar(8), getdate(), 10), '-', '/') + ' ' +
substring(convert(varchar(20), getdate(), 9), 13, 5) + ' ' +
substring(convert(varchar(30), getdate(), 9), 25, 2)

Or the stock answer is that you should do formatting like this in your front-end.


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

dineshasanka
Yak Posting Veteran

72 Posts

Posted - 2008-04-07 : 15:18:15
Select Convert(varchar , Getdate(),110) + ' ' +
Convert(varchar , Getdate(),108)

---------------------
http://dineshasanka.spaces.live.com/
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-08 : 00:52:25
Hi Ryan!
Nice to have you back.

Where have you been?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-04-08 : 04:39:36
Hi Peso

Working too hard is the short answer. I had a quiet period and was a bit bored yesterday - I'm a bit rusty when it comes to answering questions though

Back to the grindstone today, I fear...


Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -