First time posing on this forum. Need some help performing simple math with date functions in C#. Having problem with defining an integers value for search end span markers.

i.e.
EndSearch = today
BeginSearch = (today - 14 ).

I have tried using DateTime like this

DateTime EndSearch = new System.DateTime.Today().
DateTime BeginSearch = new EndSearch.DayOfYear - 14;

Not used to dealing with object oriented programming, have done mostly straight C.

Can any one point me to a good description on dealing with math computations with object oriented stuff.

Am at a complete loss.

Thanks in advance!

The DateTime struct has .Add___ methods that allow you to add values to a datetime and retrieve a new date. For getting a date in the past, you simply have to make the parameter negative. Something like

DateTime today = DateTime.Now.Date;
DateTime twoWeeksAgo = today.AddDays(-14);

Great! I'll try 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.