如何在日期中添加月份表示反转表格值? [英] How to add months in date that retrive form table value ?

查看:78
本文介绍了如何在日期中添加月份表示反转表格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我从一个表中检索日期并将该字符串值转换为DateTime格式,然后我在该日期值中添加2个月,但它在日期位置添加月份值。

例如:

日期是03/09/2015 --- dd / MM / yyyy格式

如果我在该日期添加月份,则月份数为2它成为05/09/2015,但正确的是03/11/2015。

如何实现这个目标?



这是我的程序代码



  Dim  splitstrcompdetails 作为 字符串()= strcompdetails.Split( ' 在splitstrcompdetails中我们得到了Aravind:2015年3月9日 
Dim strRegDate As DateTime = Convert.ToDateTime(splitstrcompdetails( 1 ))。ToString(stringDateFormat)' 这里stringDateFormat是dd-MMM-yyyy,我们得到strRegDate为3 / 9/2015
Dim strTotMonths 作为 Integer = Convert.ToInt32(strserialdetails)+ Convert.ToInt32(expirymonth.Value)' 她strserialdetails是2和expirymonth.Value是3所以strTotMonths是5
Dim strExpDate As 日期 = strRegDate.AddMonths(Convert.ToInt32(strTotMonths))' 但是这里我们得到strExpDate为2015年8月9日,但正确的价值是2016年3月2日





请回复asap



问候

Aravind

解决方案

Ha看看例子:



  Dim  strcompdetails 作为 字符串 =   Aravind:2015年3月9日 
Dim stringDateFormat As < span class =code-keyword> String = dd-MMM-yyyy
Dim provider As System.Globalization.CultureInfo = new System.Globalization.CultureInfo( de-DE
Dim splitstrcompdetails As String ()= strcompdetails .Split( :)
Dim RegDate As DateTime = Convert.ToDateTime(splitstrcompdetails( 1 ),provider).AddMonths( 5

Console.WriteLine( {0},RegDate.ToString(stringDateFormat))' 返回2016年2月3日





如您所见,你需要使用 CultureInfo类 [ ^ ]获得/设置特定的文化以获得适当的结果。

语言文化名称,代码和ISO值方法表 [ ^


Hi I am retrieve date from one table and converted that string value to DateTime format,and then i add 2 months in that date value,but it add month value in date place.
For Eg:
Date is 03/09/2015 --- dd/MM/yyyy format
no of months is 2, if i add month to that date it became 05/09/2015,but correct one is 03/11/2015.
How to achieve this ?

Here is my program code

Dim splitstrcompdetails As String() = strcompdetails.Split(":") ' In splitstrcompdetails we get Aravind:3/9/2015
Dim strRegDate As DateTime = Convert.ToDateTime(splitstrcompdetails(1)).ToString(stringDateFormat) 'here stringDateFormat is dd-MMM-yyyy and we get strRegDate as 3/9/2015
Dim strTotMonths As Integer = Convert.ToInt32(strserialdetails) + Convert.ToInt32(expirymonth.Value) 'her strserialdetails is 2 and expirymonth.Value is 3 so strTotMonths is 5
Dim strExpDate As Date = strRegDate.AddMonths(Convert.ToInt32(strTotMonths))' but here we get strExpDate as 8/9/2015  but correct value is 3/2/2016



Pls reply asap

Regards
Aravind

解决方案

Have a look at example:

Dim strcompdetails As String = "Aravind:3/9/2015"
Dim stringDateFormat As String = "dd-MMM-yyyy"
Dim provider As System.Globalization.CultureInfo = new System.Globalization.CultureInfo("de-DE")
Dim splitstrcompdetails As String() = strcompdetails.Split(":")
Dim RegDate As DateTime = Convert.ToDateTime(splitstrcompdetails(1), provider).AddMonths(5)

Console.WriteLine("{0}", RegDate.ToString(stringDateFormat)) 'return 03-Feb-2016



As you can see, you need to use
CultureInfo class[^] to get/set specific culture to be able to get proper result.
Table of Language Culture Names, Codes, and ISO Values Method[^]


这篇关于如何在日期中添加月份表示反转表格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆