Solved

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

Posted on 2011-02-25
12
545 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
  • 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
 
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now