Can anyone please let me know how can I get the difference between two dates?
Is there any function in c#?

I've one more question can I check for value of the textbox like if value should be atleast 500 or more??

I want to use custom validators in c#.

Recommended Answers

If you subtract two DateTime variables, the result is a TimeSpan.

Jump to Post

All 4 Replies

If you subtract two DateTime variables, the result is a TimeSpan.

Thanks Pritaeas..

Actuallly I want to calculate the age..

I think that's what pritaeas is saying. You use DateTime and you can subtract them (return TimeSpan object).

        DateTime dob = new DateTime(1980, 7, 1);
        TimeSpan difference = DateTime.Now - dob;

        Console.WriteLine(difference.TotalDays);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.