Click here to Skip to main content
12,245,566 members (59,714 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB ASP.NET VB.NET
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

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 28-Dec-12 7:04am
Comments
Sheikh Muhammad Haris 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.
Member 8197993 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
Member 8197993 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can do it like this:
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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160426.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100