How to convert from BirthDate to Age

J

Jesper Pedersen

Hi ! please help - I have tabel with a Birthday column in a access database
and need to show the age in a datagrid.
-------------------------------------------------------------------
found this little code:
-------------------------------------------------------------------
<%
DateTime birthDate = new DateTime(1986, 12, 25); //A wonderful day for me!
TimeSpan age = DateTime.Now - birthDate;
//age contains my age (the time from my birthday to the current time)
Response.Write("I am " + (age.TotalDays/365.25) + " days old!");
%>
--------------------------------------------------------------------
It works fine, but how should i do in my example here:
--------------------------------------------------------------------
<%
OleDbConnection Conn;
OleDbCommand Cmd;
Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\database.mdb");
Cmd = new OleDbCommand("SELECT Birthday FROM tabel ,Conn);

Conn.Open();
DataGrid1.DataSource = Cmd.ExecuteReader();
DataGrid1.DataBind();
Conn.Close();
%>
<asp:DataGrid id="DataGrid1" runat="server">
<asp:TemplateColumn HeaderText="Age">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Birthday") %>
</ItemTemplate>
</asp:TemplateColumn>
</asp:DataGrid>

Instead of the Birthday i want the Age to be printet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top