Click here to Skip to main content
15,888,579 members
Articles / Web Development / ASP.NET

How i convert dataetime to int and string to Int

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
12 Jan 2013CPOL 4.5K  
DateTime datenow = DateTime.Now;int age=0;age =Convert.ToInt32(ddlyear.SelectedItem.Text).ToString();int result = 0;result =Convert.ToDateTime(datenow).ToString() - Convert.ToInt32(age).ToString();txtage.Text = result.ToString();

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
12 Jan 2013David_Wimbley
It looks like your trying to get the age in years using DateTime.Now and the birth date.This will do just that.DateTime today = DateTime.Today;int calc1 = (today.Year * 100 + today.Month) * 100 + today.Day;int calc2 = (dateOfBirth.Year * 100 + dateOfBirth.Month) * 100 +...
Please Sign up or sign in to vote.
12 Jan 2013Jibesh
The code has serious issues it wont even compile.You are totally confused with the conversions. I would suggest understand the basics of assignment operations too.you are trying to store a string data into an integer variable 'age' at the following location which is wrong you never store a...
Please Sign up or sign in to vote.
13 Jan 2013Andreas Gieriet
Your code is rather weird.You seem to have little understanding of the C# type system[^].You seem to try to calculate a start date/time by subtract some "age" from "now".What is "age"? seconds, minutes, hours, days, weeks, monts, years, centuries, mayan-cycles ;-)...?Anyways: when...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions