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

    How to convert d/MM/yyyy data to dd/MM/yyyy in sql server table?

    I have create one field in sql server database as nvarchar datatype and store some date like 'd/MM/yyyy' and 'dd/MM/yyyy' format previously. Now i want to get all data in 'dd/MM/yyyy' format using query it is possible?
  • #645436
    Hi Ravindran,

    First cast the varchar field to date time and then convert that into the format you want.

    Check below query,


    select CONVERT(VARCHAR(10),cast(StartDate as datetime),101) [DD/MM/YYYY] from TestTable


    Let me know if you have any doubt in this.


    Regards,
    Asheej T K

  • #645511
    Hi Asheej

    I try this before but result not come error only come like nvarchar not convert to datetime because already d/MM/yyyy format also available in the field data. if only dd/MM/yyyy format data is there then your query works fine.

    Regards
    N.Ravindran
    Your Hard work never fails

  • #645528
    Ravindran,

    It is working fine in my end. If your field datatype is NVARCHAR then change the query from varchar to NVARCHAR. Please try below code,

    select CONVERT(NVARCHAR(10),cast([StartDate] as datetime),101) [DD/MM/YYYY] from TEST

    Let me know the output.


    Regards,
    Asheej T K

  • #645585
    Thaks asheej yes its work fine
    Regards
    N.Ravindran
    Your Hard work never fails


  • 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.