我需要选择某一天使用.addmonths(1.0)插入 [英] I need to select a certain day to insert using .addmonths(1.0)
问题描述
我有一个应用程序,可以存储项目到期时间以及开始日期和结束日期。例如:如果它是在每月1日到期,开始日期是12-15-2012,结束日期是03-15-2013,我每个月都会在sql数据库中插入一行。总计4行。
基本上我想插入表格中所有信息的第一行,然后是3行,截止日期为1下个月等等。
喜欢:
到期日:
01-01-2013
02-01-2013
03-01-2013
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想要使用表格上选择的开始日期,每个只需加1个月行c reated但是选择当天添加,1st也
任何人都可以帮帮我吗?
对不起,如果这样做的话没有意义,我很累。
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.
推荐答案
你可以这样做:
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.
这篇关于我需要选择某一天使用.addmonths(1.0)插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!