Solved

date & time formatting

Posted on 2012-04-05
6
195 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 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