You must Sign In to post a response.
  • Category: SQL Server

    Date function Problem

    Hi all..The below query will give the result 8/01/2012

    select CONVERT(CHAR(10), rtrim(cast(Datepart(mm, DATEADD(mm, -1, Getdate())) AS char(2)))+ '/01/' + cast(DATEPART(yyyy, DATEADD(mm, -1, Getdate())) AS char(4)))


    But i want this query to give input like 1-Aug-2012


    Can any one help?
  • #687974
    Hi..

    you can use this query.

     
    select replace(convert(varchar,getdate(),106),' ','-')

  • #687981
    Hi,

    Use below query for "DD-MM-YYYY" format:


    SELECT REPLACE(CONVERT(VARCHAR, SYSDATETIME(), 106),' ','-')

    Hope it'll help you.
    Regards
    Ajatshatru

  • #688261
    try this code


    SELECT RIGHT('0' + DATENAME(DAY, Getdate()), 2) + '-' + DATENAME(MONTH, Getdate())+ '-' + DATENAME(YEAR, Getdate()) AS Date


    hope this will help you


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.