Solved

ms sql server 2005 - get day from date..(ie..Wednesday)

Posted on 2011-02-25
12
577 Views
Last Modified: 2012-05-11
I have this but I need to convert to see what actual day it is..like wednesday..monday..etc

 DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
0
Comment
Question by:GlobaLevel
[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
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34981661
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
SELECT DATENAME(dw, @CURR_DATE) AS 'Day'

Open in new window

0
 
LVL 8

Expert Comment

by:rushShah
ID: 34981664
you can do like this,
select DATENAME(WEEKDAY, getdate())

Open in new window

0
 
LVL 5

Expert Comment

by:scgstuff
ID: 34981671
You can use DatePart to get the numeric day of week.  Then you could use that to give you the word for the day of week.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 7

Expert Comment

by:ncheung
ID: 34981675

Try using DATEPART
http://msdn.microsoft.com/en-us/library/ms174420.aspx

Example:
SELECT DATEPART(dw, GETDATE())
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 34981679
so for examply need to convert to
'Friday' or
'Friday February 15, 2011'

both options would be great...
0
 
LVL 7

Expert Comment

by:ncheung
ID: 34981734
DATENAME will work as illustrated by previous responses.
0
 
LVL 5

Expert Comment

by:scgstuff
ID: 34981745
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
select datename(weekday, @CURR_DATE) + ' ' + convert(varchar, @CURR_DATE) as mydate

Result is: Friday Feb 25 2011 11:49AM

0
 
LVL 8

Expert Comment

by:rushShah
ID: 34981766

DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
SELECT CONVERT(VARCHAR(20), @CURR_DATE, 100)--o/p Feb 25 2011 1:29PM

or

DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
select DATENAME(WEEKDAY, @CURR_DATE)--o/p Friday

Open in new window

0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34981770
SELECT DATENAME(WEEKDAY, getdate()) 
+ ' ' + CONVERT(VARCHAR(12), GETDATE(), 100)

Open in new window


Friday Feb 25 2011
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34981784
Applying in your code
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
SELECT DATENAME(WEEKDAY, @CURR_DATE) 
+ ' ' + CONVERT(VARCHAR(12), @CURR_DATE, 100)

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34981801
SELECT DATENAME(WEEKDAY, getdate()) 
+ ' ' + DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY]

Open in new window


Friday February 25, 2011
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34981806
Modifying your query
DECLARE @CURR_DATE smalldatetime
 SET  @CURR_DATE = ISNULL(@CURR_DATE, getDATE())
SELECT DATENAME(WEEKDAY, @CURR_DATE) 
+ ' ' + DATENAME(MM, @CURR_DATE) + RIGHT(CONVERT(VARCHAR(12), @CURR_DATE, 107), 9) AS [Month DD, YYYY]

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

734 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