?
Solved

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

Posted on 2011-02-25
12
Medium Priority
?
583 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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.
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.
Suggested Courses

762 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