Coding a TimeSpan

D

Dennis D.

Hello:
I want to subtract a timespan from the selectionrange.start of a month
calendar.

The selectionrange.start of a month calendar is a date, and it is possible
to subtract a timespan from a date and get a date, from which I will extract
the day.

How do I assign an integer to represent an 'n' day timespan, especially
without using ticks?

If I subtract 4 days from the 2nd day of the month using integers I get a -1
(no date) for a result.
The result should be 29, the 29th day of the previous month.

So far, the timespan error indicates the parts of the timespan are read
only, and I haven't been able to negotiate a constructor to make the
timespan day = some integer variable, and I haven't found any code examples
assigning a value to a timespan.

More or less:
Thursday = 4
selectionrange.start - Thursday
Same as 3/25/06 - 4 days = 3/21/06

Thank You,

Dennis.
http://www.dennisys.com/
 
A

Armin Zingler

Dennis D. said:
Hello:
I want to subtract a timespan from the selectionrange.start of a
month calendar.

The selectionrange.start of a month calendar is a date, and it is
possible to subtract a timespan from a date and get a date, from
which I will extract the day.

How do I assign an integer to represent an 'n' day timespan,
especially without using ticks?

ts = new timespan(n, 0, 0, 0)

- or -

ts= timespan.fromdays(n)

If I subtract 4 days from the 2nd day of the month using integers I
get a -1 (no date) for a result.
Code?

The result should be 29, the 29th day of the previous month.

So far, the timespan error indicates the parts of the timespan are
read only, and I haven't been able to negotiate a constructor to
make the timespan day = some integer variable, and I haven't found
any code examples assigning a value to a timespan.

More or less:
Thursday = 4
selectionrange.start - Thursday
Same as 3/25/06 - 4 days = 3/21/06

dim dt1, dt2 as datetime

dt1 = #3/25/2006#
dt2 = dt1.adddays(-4)

- or -

dim ts as new timespan(4, 0, 0, 0)

dt2 = dt1.subtract(ts)


Armin
 
H

Homer J Simpson

Dennis D. said:
Hello:
I want to subtract a timespan from the selectionrange.start of a month
calendar.

Like

Dim today As System.DateTime
Dim answer As System.DateTime
today = System.DateTime.Now
answer = today.AddDays(-36)

??
 

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

Similar Threads


Top