SQL Server - Formatting Dates

Discussion in 'SQL Server' started by duffy202, Aug 4, 2011.

  1. duffy202

    duffy202 New Member

    Joined:
    Aug 4, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi Guys,

    I run the following query:

    DECLARE @Today DATETIME; SET @Today =GETDATE()
    SELECT Case.CustomerName, Case.CreatedOn
    FROM MSCRM.dbo.Case Case
    WHERE Case.CreatedOn BETWEEN @StartDate AND @Today
    ORDER BY Case.CreatedOn


    It gives the out put:
    03/22/2011 8:12:17 AM Microsoft Corporation (US Date & Time)

    Can anyone show me how i should ammend my code above so the output is like this:
    22/03/2011 Microsoft Corporation (UK Date)

    Thanks Guys,
    M
     
  2. sql-programs

    sql-programs New Member

    Joined:
    Oct 21, 2009
    Messages:
    14
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software Developer
    Home Page:
    http://www.sql-programmers.com
    Hi,

    Please use the below link more date time format conversion

    Time and Date Formats

    We can display the date and time data in many different formats using the CONVERT function with different styles.

    Example:
    view plaincopy to clipboardprint?

    Select getdate() Result: 2009-10-26 13:39:59.543

    Different style numbers result in different formats of date time display.
    Style Result
    0 or 100 Oct 26 2009 1:41PM
    1 10/26/2009
    2 09.10.26
    3 26/10/09
    4 26.10.09
    5 26-10-09
    6 26 Oct 09
    7 Oct 26, 09
    8, 24, or 108 13:42:23
    9 or 109 Oct 26 2009 1:42:42:543PM
    10 10-26-09
    11 09/10/26
    12 091026
    13 26 Oct 2009 13:46:14:590
    14 13:46:25:967
    20 2009-10-26 13:48:51
    21 or 25 2009-10-26 13:48:29.340
    22 10/26/09 1:48:53 PM
    23 2009-10-26
    24 13:48:53
    101 10/26/2009
    102 2009.10.26
    103 26/10/2009
    104 26.10.2009
    105 26-10-2009
    106 26 Oct 2009
    107 Oct 26, 2009
    110 10-26-2009
     
  3. mountainman

    mountainman Banned

    Joined:
    Feb 6, 2012
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Yes, i agree with above answer.
     
  4. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    http://www.ifourtechnolab.com/
    Hi,

    You can use the following to convert the date format

    Thnaks
     
    Last edited: Jan 24, 2017
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice