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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Calculated Field

Thread ID:

Created:

Updated:

Platform:

Replies:

128426 Jan 20,2017 03:18 PM UTC Jan 23,2017 11:48 AM UTC WinForms 1
loading
Tags: PivotGridControl
Tim Larson
Asked On January 20, 2017 03:18 PM UTC

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 11:48 AM UTC

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.

Warning Icon 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.Close Icon

;