Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

date & time formatting

Posted on 2012-04-05
6
Medium Priority
?
197 Views
Last Modified: 2012-04-05
in Sql Server 2K8 - is there a slick method of displaying date and time so that the output would be something like:
04/05/2012 9:15 am
with one command?
and if so how about options to use 12 or 24 hour clock?

thanks ...
0
Comment
Question by:dgrafx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:wshark83
ID: 37811658
here's a useful link which converts dates to various formats:

http://www.sqlusa.com/bestpractices/datetimeconversion/

basically you need to use the convert(datetime,<datefield>) functions
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 37811662
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 37811845
There is no out of the box CONVERT option that formats the date as mm/dd/yyyy hh:mm AM (or PM) or mm/dd/yyyy hh:mm (24h), you'll need to use the available formats and do some string manipulation.
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 7

Expert Comment

by:micropc1
ID: 37812009
Right, like wdosanjos said you'll need to do something like.. (not tested)

CONVERT(varchar(50), GETDATE(), 101) + ' ' + RIGHT(CONVERT(varchar(50), GETDATE(), 100), LEN(CONVERT(varchar(50), GETDATE(), 100)) - 12)

This may also help.. http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 
LVL 25

Author Comment

by:dgrafx
ID: 37812051
isn't there a new time format ??? like convert(time,getdate()) ?
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 37812140
time is a data type not a format, but could do something like this:
-- mm/dd/yyyy hh:mmAM
select convert(varchar(20), getdate(), 101) + ' ' + convert(varchar(20), convert(time, getdate()), 100)

-- mm/dd/yyyy hh:mm
select convert(varchar(20), getdate(), 101) + ' ' + left(convert(varchar(20), convert(time, getdate(), 121)), 5)

/* Output

-----------------------------------------
04/05/2012 11:18AM


--------------------------
04/05/2012 11:18

*/

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question