Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an application that stores when projects are due along with a start date and end date. Ex: if it is due on the 1st of each month and the start date is 12-15-2012 and the end date is 03-15-2013, I am inserting a row into sql database for each month. Total of 4 rows.

basically i want to insert the first row with all of the info on the form, then 3 more rows with a due date of the 1st for the next month and so on.

like:
DueDate:
01-01-2013
02-01-2013
03-01-2013

VB
If (value = 2) Then
Dim ddate As Date'DueDate
ddate = Sdate.AddMonths(1.0)'add one month but select the day of the month to insert


i want to use the start date selected on the form and just add 1 month for each row created but select the day of the month to add, the "1st" also

Can anyone help me out?
sorry if this makes no sense, i am verry tired.
Posted
Comments
[no name] 28-Dec-12 12:46pm    
Not clear enough, Do you want to save day name (Monday etc) with each of the three rows or what ?

Also provide details how are you adding first row, so that it would be clear how to add others.
PTG.Jake 28-Dec-12 13:28pm    
i have a DDL of 1-28 for the day due of the month, if i choose 1 for day due, i want to insert a row into my table with the startdate(basically a timestamp) the next row will insert the startdate + 1 month but instead of adding 30 days for the +1month, i want it to insert the next month after the start date with 01 being the day due. Not just add 30 days, i want to actually tell it what day to insert for that month.
Sergey Alexandrovich Kryukov 28-Dec-12 14:24pm    
No a valid question, "Can anyone help me out?". Many will be able to help, if you explain what you really want to do. And ask a question.
—SA
PTG.Jake 28-Dec-12 14:45pm    
Ok since this is going nowhere. lets say i do this:
dim d as date
d = date.today
insert into table (duedate) values('" & d.addmonths(1.0).day5 of new month

HOW do i add one month to todays date but select the day i want, not just addmonth?

1 solution

You can do it like this:
C#
DateTime date = DateTime.Now;
date = date.AddMonths(1);
// set our next date to be the first of the next month
date = date.AddDays((date.Day - 1) * -1);
string dateText = date.ToShortDateString();


Just use the offset of the day of the month to adjust what day you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900