Set dates

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

Is there an easy way to set a date to the beginning of the month? Say I
want to add 7 months to today (except that today is not a good reference as
it would figure out to be March 1)...say I add 7 months to 09/06/2004 and I
get a returned date of 03/06/2005. What I then need to do is to take that
date and make it 03/01/2005. Is there an easy way to do this?

Thanks for the information.

Brad
 
Dim dt As DateTime = Today.AddMonths(7)
Dim days As Integer = dt.Day - 1
dt = dt.AddDays(-days)

Think that would do it,
Greg
 
Brad said:
Is there an easy way to set a date to the beginning of the month? Say I
want to add 7 months to today (except that today is not a good reference as
it would figure out to be March 1)...say I add 7 months to 09/06/2004 and I
get a returned date of 03/06/2005. What I then need to do is to take that
date and make it 03/01/2005. Is there an easy way to do this?

Thanks for the information.

Brad


Dim TempDate as DateTime = DateTime.Now.AddMonths(7)
Dim TargetDate as New DateTime(Fred.Year, Fred.Month, 1, 0, 0, 0)
 
Dim TempDate As DateTime = DateTime.Today.AddMonths(7)
Dim TargetDate As New DateTime(TempDate.Year, TempDate.Month, 1)

I like your way better, seems cleaner.

BTW, who's Fred? :^)

Greg
 

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

Back
Top