Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add month to a date field

Status
Not open for further replies.

Bersani

Programmer
Nov 10, 2011
48
US
I need to a add a month to a date field. I do not know how to format the date field in order to do the calculation. I have tried DateAdd with no luck. The date field is called baseline; it is formatted as short date. I want to make a label that gives a projected date 30 days (or 1 month)into the future.
 
DateAdd is SQL Server code:
Code:
SELECT DATEADD(m,1,GETDATE())

This is vb code using the .NET framework:
Code:
Dim x As Date = DateTime.Now.AddMonths(1)
 
The start date that I am using is contained in a field name "baseline". I am using Visual Studio 10 with .net 4 framework with a MySql database. Do I need to modify the field in order to use it with adding 30 days?
 
I don't understand your question. If you have a field called "baseline" in your database, and want to display it on the page and add 30 days either:
1.) Change your select statement to add the days OR
2.) Change the value in the code-behind after you retrieve your data.

Pick which way you want to do it and use the appropriate code above. You just need to use your "baseline" field instead of getdate() OR datetime.now.

Post back with any questions
 
I get the error message:
Compiler Error Message: BC30451: 'm' is not declared. It may be inaccessible due to its protection level.

Source Error:



Line 121: <br />
Line 122: <br />
Line 123: <asp:TextBox ID="TextBox3" runat="server" Text='<%# DateAdd(m,1.baseline) %>'></asp:TextBox>
Line 124: <br />
Line 125: <br />

 
Dear jbenson001

YOur suggestions work fine except when I replace NOW or GETDATE with the field name.

 
Code:
SELECT DATEADD(m,1,GETDATE())
is SQL Server Code and needs to be done in your SQL or Stored Procedure
Code:
SELECT DATEADD(m,1,BaseLine) from <YourTable> ... etc
 
I created a stored procedure but I got an error. I keep on getting an error message for (m,
Where should I put the stored procedure?
 
What do you mean you get an error? What do you mean where should you put the SP? The SP gets compiled on your SQL Server.
 
I am not using SQL Server (this time). I am using MySQL database. I do not know how to program in PHP and prefer using Visual Studio.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top