Crazy trouble on date

B

Budd

Hi everyone

i got a problem on date, it is...

1, i get the date from calendar component

2, compare today and selected date is equal (compare method)

3 count the number of day between this 2 date

but i cannot find any method to count the number of day between this 2 date

just like...2006/4/5 - 2006/4/1....i will get the result 4

anyone know how to do subtrust the date???

thx a lot
 
K

Kevin Spencer

Hi Budd,
1, i get the date from calendar component
Use the SelectedDate property, or the SelectedDates property, depending upon
which SelectionMode you're using. This returns a DateTime.
2, compare today and selected date is equal (compare method)
Assuming that you only need to compare to the day, use the DateTime.Subtract
method. The DateTime.Subtract method is an instance method of the DateTime
structure, and takes another DateTime as an argument. It returns a TimeSpan,
indicating the difference between the 2 Dates. The TotalDays member of the
TimeSpan is a double which indicates the total number of days in the
TimeSpan. Since you only want to compare to the Day, you need to eliminate
fractional days from the value. This is easily done by casting the value as
a long.

If the result is negative, the second date is greater than the date
subtracting it, by that many days. If you just need to know if the dates are
the same day, all you need to do is compare the long integer result to 0.
3 count the number of day between this 2 date
Same deal as number 2. If you only need to know the number of days, use
Math.Abs to get rid of any negativity.
anyone know how to do subtrust the date???
Nah, sorry, don't know that one.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top