Results 1 to 5 of 5

Thread: get month and year and day in query

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    get month and year and day in query

    i have following query


    SELECT DISTINCT DATEADD(day, 0, DATEDIFF(day, 0, starttime)) as date FROM table

    and these me return like this

    2011-02-03 00:00:00.000


    i want to convert that query that give reult like this

    thursday ,feburay 2,2011

    how to do this ??

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: get month and year and day in query

    Assuming you have your date in @date variable (otherwise replace with your date column name):
    sql Code:
    1. SELECT DATENAME(weekday, @date) + ', '
    2.      + DATENAME(month,   @date) + ' '
    3.      + DATENAME(day,     @date) + ', '
    4.      + DATENAME(year,    @date) + ' '
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: get month and year and day in query

    Note that we did that because none of the CONVERT options satisfy your need. If you can be content with one of these predefined formats, then you should prefer CONVERT.
    http://msdn.microsoft.com/en-us/library/ms187928.aspx
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    270

    Re: get month and year and day in query

    it should be like thi s??

    DECLARE @VariableName datetime

    set @VariableName = SELECT DISTINCT DATEADD(day, 0, DATEDIFF(day, 0, starttime)) as date FROM table

    this giving me error ..

    Incorrect syntax near the keyword 'SELECT'.

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: get month and year and day in query

    sql Code:
    1. DECLARE @date DATETIME
    2. SELECT DISTINCT @date = DATEADD(day, 0, DATEDIFF(day, 0, starttime)) FROM table1
    3. SELECT DATENAME(weekday, @date) + ', '
    4.      + DATENAME(month, @date) + ' '
    5.      + DATENAME(day, @date) + ', '
    6.      + DATENAME(year, @date) + ' '
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width