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

Calculate date column in grid

Hello,

I am having a hard time calculating number of day between a date column ( DataOD.ExpirationDate) with the current date and display it in the grid column.


Could you please help?


 <GridColumn Field=@nameof(DataOD.ExpirationDate) HeaderText="Expiration Date" Format="dd-MMM-yy" TextAlign="TextAlign.Center" Width="15" Visible=true ShowInColumnChooser=true AllowEditing=false> </GridColumn>

                                <GridColumn Field=@nameof(DataOD.ExpirationQty) HeaderText="Expiration Qty" Format=N0 TextAlign="TextAlign.Center" Width="15" Visible=true ShowInColumnChooser=true AllowEditing=false> </GridColumn>

                                <GridColumn Field=@nameof(DataOD.DayToExpire) HeaderText="Remaining Shelf Life (M)" TextAlign="TextAlign.Left" Width="15" Visible=true ShowInColumnChooser=true AllowEditing=false>

                                    <Template Context="GridInsideDialog">

                                        @{

                                            var value = (GridInsideDialog as DataOD);

                                            var CurrentDate = DateTime.Now;

                                            var x = value.ExpirationDate;

                                            var Days = 0;

                                            Days = CurrentDate.Date - x;

                                            <div>$@Days</div>

                                                                                    }

                                    </Template>

                                </GridColumn>



1 Reply 1 reply marked as answer

SP Sarveswaran Palani Syncfusion Team December 9, 2022 04:12 AM UTC

Hi Sao,

Greetings from Syncfusion support.

From your query, we prepared sample similar to your requirement. Kindly refer the attached sample and perform calculation based on your requirement. If you’re facing any issue, please get backs to us.

Regards,
Sarvesh


Attachment: SfGridDateColumn_9b22b2c7.zip

Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon