none
get the day from date value in SQL Server RRS feed

  • Question

  • Hello,

     

    I want to know how can I (in sql server) get the day  of week(eg Mon, Tue, Wed, etc) when a specific date is being given to the stored procedure. The day number will also do fine!!

     

    In other words...I want to send a date to a stored procedure. Before anything in the sp can happen, I need to know the DayOfWeek the specified date falls on (day number also fine). Once I know the DayOfWeek I can continue with the rest of the work that actually needs to happen in the sp.

     

    I know I can get the DayOfWeek in vb itself, but it would be easier if I can determine this in SQL Server and then just pass the date through as a paramater. If I have to get the DayOf Week in vb then I have to add a second paramater (one for DOW and one for the Date).

     

    I hope the question is clear!?!

    Friday, May 11, 2007 10:53 AM

Answers

  • Give a look to books online to find the information you need.  For a number to designate the day of the week, give a look to the DATEPART functon.  For the name of the day of the week give a look to DATENAME.  Hang on and I'll get you a couple of examples.

     

    Here is a quick example.  Note that DW is the designation for "Day of the Week:"

     

    select datepart (dw, '5/11/7') as dayOfTheWeek,
           datename (dw, '5/11/7') as NameOfDay

     

    /*
    dayOfTheWeek NameOfDay                     
    ------------ ------------------------------
    6            Friday
    */

    Friday, May 11, 2007 11:01 AM
    Moderator

All replies

  • Give a look to books online to find the information you need.  For a number to designate the day of the week, give a look to the DATEPART functon.  For the name of the day of the week give a look to DATENAME.  Hang on and I'll get you a couple of examples.

     

    Here is a quick example.  Note that DW is the designation for "Day of the Week:"

     

    select datepart (dw, '5/11/7') as dayOfTheWeek,
           datename (dw, '5/11/7') as NameOfDay

     

    /*
    dayOfTheWeek NameOfDay                     
    ------------ ------------------------------
    6            Friday
    */

    Friday, May 11, 2007 11:01 AM
    Moderator
  • Code Snippet
    SELECT DATENAME (DW,GETDATE())

     

     

    Gurpreet S. Gill

    Friday, May 11, 2007 11:13 AM
  • Thanks guys!! I have been looking in the help files for SQl Server (2005), but I didn't spot it!!

     

    Now that I have seen the solution, I remember that I have actually used it some time ago!!

    Friday, May 11, 2007 11:59 AM
  • To get a constant day number, you should check out the following description:

    http://www.lazerwire.com/2011/10/sql-day-of-week.html

    Wednesday, October 12, 2011 6:39 PM
  • thnks it works for me.....
    Saturday, July 6, 2013 8:07 AM