Skip to content

In GridView Date should be displayed in correct format

narasiman rao

Asked Dec 27, 2012, 2:03 AM EST2 answers
Share
LinkedInX
 i inserted all the record in the database.

database type as

   DOB                 datetime
Wedding day      datetime

i have one button view.when i click that button all record should be displayed in the Grid View.

Code
Grid view  Button code as follows;


sql ="select Name,DOB,Mobileno,Weddingday,Email from BIrthDayWish where Active ='A' ORDER BY Name";
        Dr = SCon.ReadSql(Sql);
        GridView1.DataSource = Dr;
        GridView1.DataBind();
        GridView1.Visible = true;

output in Grid View  as follows

Name        DOB               Mobile no        Wedding day               Email
ram  22/12/1986 12:00:00 AM  9945598565  22/12/2009 12:00:00 AM     [email protected]


but i want the output in grid view related to DOB and Wedding day date to be shown as

Name        DOB               Mobile no        Wedding day               Email
ram        22/12/1986        9945598565        22/12/2009            [email protected]

Not needed a
DOB           Wedding Day
12:00:00 AM   12:00:00 AM


Code
sql ="select Name,DOB,Mobileno,Weddingday,Email from BIrthDayWish where Active ='A'
ORDER BY Name";




from my above query how to correct the query and get the output as follows
Name        DOB               Mobile no             Wedding day               Email
ram        22/12/1986       9945598565        22/12/2009            [email protected]

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Ganesh M
    0
    Try this

    sql ="select Name,CONVERT(varchar(15),DOB,103) as DOB,Mobileno,CONVERT(varchar(15),Weddingday,103) as Weddingday,Email from BIrthDayWish where Active ='A' 
    ORDER BY Name";
    0
  • Akkiraju Ivaturi
    0
    Is the database SQL Server 2008? If so, you have a data type called Date and you need not use the datetime type. Otherwise, you may have to use the function to get the datepart of the datetime value.

    Though the CONVERT function has performance issues, but still it is negligible in this case and also gives you more flexibility to display dates in many formats.

    For example, the following displays date in different format:

    SELECT CONVERT(VARCHAR(10),GETDATE(),111)

    2012/12/27
    0