Hi, I will be getting from source the date format as string mm/dd/yyyy ("11/04/1920").
I would like to know is there any easy logic to find out the Age.
I would like to know if the Age is >=16
Hi, I will be getting from source the date format as string mm/dd/yyyy ("11/04/1920").
I would like to know is there any easy logic to find out the Age.
I would like to know if the Age is >=16
Try...
bool isOver16 = DateTime.Now.AddYears(-16) >= DateTime.Parse("11/04/1920", CultureInfo.GetCultureInfo("en-US"));
Check this method:
string example = "11/04/1920";
DateTime date = DateTime.Parse( example, CultureInfo.GetCultureInfo( "en-US" ) );
DateTime today = DateTime.Today;
int age = today.Year - date.Year;
if( date.AddYears( age ) > today ) age -= 1;
if( age >= 16 )
{
// . . .
}
Hi, this below line of code is throwing error...can you pls clarify ? age-=1
if( date.AddYears( age ) > today ) age -= 1;
I just need to return the Age...thats it
Step 1: Create a method to Check the Age
public static int GetAge(DateTime dob)
{
return DateTime.Now.AddYears(-dob.Year).Year;
}
Step 2: Call the method
string inputDate="11/04/1920";
if(GetAge(Convert.ToDateTime(inputDate))>=16)
{
// TODO:
}
else
{
//TODO:
}
8 people are following this question.
Insert a node as child ,before or after a node in nested dynamic JSON Node using C#
Visual Studio 2019: Undefined behavior in a C++/CLI wrapper project.
Example for how to get Package Metadata from Azure DevOps Rest-Api Artifacts using c#
How to collapse individual nested grids/stackpanels inside a grid?