Solved

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

Posted on 2011-02-25
12
537 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article I will describe the Copy Database Wizard 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.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 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

14 Experts available now in Live!

Get 1:1 Help Now