We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Calculated Field

Thread ID:

Created:

Updated:

Platform:

Replies:

128426 Jan 20,2017 10:18 AM Jan 23,2017 06:48 AM Windows Forms 1
loading
Tags: PivotGridControl
Tim Larson
Asked On January 20, 2017 10:18 AM

I have a date in my dataset and I would like to break it down to have a column for the year, month and day.  How can I do this?

Thanks,
Tim

Mohanraj Gunasekaran [Syncfusion]
Replied On January 23, 2017 06:48 AM

Hi Tim, 

Thanks for using Syncfusion products, 

We do not have the direct support to split the DateTime column as a Day, Month and Year from DataSet. But you can achieve your scenario by converting the dataset to DataTable. Please refer the below code snippet, refer the below screenshot and refer the attached sample, 

Code snippet 
DataTable ds = new DataTable(); 
String commandstring = "select * from Employees"; 
String connection = @"Data Source=" + FindFile("NorthwindwithImage.sdf"); 
SqlCeDataAdapter da = new SqlCeDataAdapter(commandstring, connection); 
try 
{ 
    da.Fill(ds); 
} 
catch (SqlException ex) 
{ 
    MessageBox.Show(ex.ToString()); 
} 
 
ds.Columns.Add("Date"); 
ds.Columns.Add("Month"); 
ds.Columns.Add("Year"); 
 
for (int i = 0; i < ds.Rows.Count; i++) 
{ 
    DateTime date = Convert.ToDateTime(ds.Rows[i]["BirthDate"]); 
    ds.Rows[i]["Date"] = date.ToString("dd"); 
    ds.Rows[i]["Month"] = date.ToString("MM"); 
    ds.Rows[i]["Year"] = date.ToString("yyyy"); 
 
} 

Screenshot 
 
 
 
Sample link: PivotGrid 

Please let us know if we misunderstood your query. 

Regards, 
Mohanraj G. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;