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. Image for the cookie policy date

Calculated Field

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

1 Reply

MG Mohanraj Gunasekaran Syncfusion Team 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. 


Loader.
Up arrow icon