Reputation: 97
This is my code by which i bind dropdownlist data from sql..i want to remove the time part from date...
string query = "select distinct PaperStartDate from HMDPaperManage ";
ddlPaperDate.DataSource = clsSqlFunctions.GetSelectedData(query);
ddlPaperDate.DataTextField = "PaperStartDate";
ddlPaperDate.DataBind();
23/04/2014 00:00:00:00
and i want
23/04/2014
Upvotes: 1
Views: 1619
Reputation: 1100
You should trim it in DB query
string query = "select distinct CONVERT(VARCHAR(10),PaperStartDate , 111) from HMDPaperManage ";
Check this for other formats
http://technet.microsoft.com/en-us/library/ms187928.aspx
Upvotes: 1
Reputation: 3110
You can just update your Query like
string query = "select distinct CONVERT(VARCHAR(12),PaperStartDate,103) as 'PaperStartDate' from HMDPaperManage ";
ddlPaperDate.DataSource = clsSqlFunctions.GetSelectedData(query);
ddlPaperDate.DataTextField = "PaperStartDate";
ddlPaperDate.DataBind();
In CONVERT(VARCHAR(12),PaperStartDate,103), 103 is the format code. You can have a lot of format codes. Below is the link for the other format codes: http://msdn.microsoft.com/en-us/library/ms187928.aspx
Upvotes: 1
Reputation: 6876
Set the "DataTextFormatString to "d" i.e.
ddlPaperDate.DataTextFormatString = "d";
This gives the added benefit that you can change up how the date is formatted based on standard string.format() conversions.
For more info, see here
Upvotes: 1
Reputation: 26209
You can replace the DropDownList values asbelow:
for(int i=0;i<ddlPaperDate.Items.Count;i++)
{
ddlPaperDate.Items[i]=DateTime.ParseExact(ddlPaperDate.Items[i].Text,
"dd/MM/yyyy HH:mm:ss",CultureInfo.InvariantCulture).ToString("dd/MM/yyyy");
}
Upvotes: 2
Reputation: 7556
string query = "select distinct DATEADD(dd, DATEDIFF(dd, 0, PaperStartDate), 0) from HMDPaperManage ";
try this solution
DATEADD(dd, DATEDIFF(dd, 0, PaperStartDate), 0)
should take only date part
Upvotes: 2