Solved

date & time formatting

Posted on 2012-04-05
6
196 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

622 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