Home  • Programming • ADO.NET

Convert age into date and date into age in #C.NET

1 csharp-dot-net Date into age
 Double days = (DateTime.Now - row.Field<DateTime>("dob").TotalDays;
                    if (days <= 31)
                    {
                        txtAge.Text = Math.Round(((DateTime.Now - row.Field<DateTime>("dob").TotalDays)).ToString();
                        cmbAgeUoM.Text = "Days";
                    }
                    else if (days > 31 && days <= 365)
                    {
                        txtAge.Text = Math.Round(((DateTime.Now - row.Field<DateTime>("dob").TotalDays / 30)).ToString();
                        cmbAgeUoM.Text = "Months";
                    }
                    else
                    {
                        txtAge.Text = Math.Round(((DateTime.Now - row.Field<DateTime>("dob").TotalDays / 365)).ToString();
                        cmbAgeUoM.Text = "Years";
                    }

Comments 0


Copyright © 2024. Powered by Intellect Software Ltd