Member Avatar for photo123

I have 2 textboxes on a form that accept dates. I dont have a drop down box, I just let the user enter the date themselves. I then want to take the dates entered from those two boxes and figure out how many days apart they are. I'm not sure what I can use for this. Do anyone know what I should read about to figure this out? Thanks.

Therein lies madness.

I'm not kidding. If you research our date system you find that due to history some days are missing so many days between dates only works for specific years.

As to reading I'd look up DateDiff or https://www.google.com/search?&q=c%23+datediff

Does this have to work for say dates BC and AD and all time?

Member Avatar for photo123

No it doesn't need to include AD and BC

So what dates need to be supported?
Why not use DateDiff? (I already noted where it can fail.)

You can use DateTime.Parse() to convert your string to a DateTime. DateTime variables can be subtracted resulting in a TimeSpan containing the difference.

commented: What do you think about their exclusion of AD and BC dates? +15

Also expecting a user to properly type the date in the correct format is going to create a lot of heartache for you. I would suggest the DateTimePicker control available in the default toolbox in a Windows form project. Now not only will the date be in the correct format it will also be a DateTime type which has methods to perform date math

Have missed the AD/BC requirement, wonder why he needs it...

Be a part of the DaniWeb community

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