简体   繁体   中英

Date format and adding a day in vb.net

I am trying to add a day to a date retrieved as below

//reading fromdatabase
Dim expenddt_ As String = rdr("Expected_End_Date").ToString

Dim dt_1 As Date = Date.Parse(expenddt_)
Dim expenddt As String = dt_1.ToShortDateString()
txtenddt.Text = expenddt

Suppose if expenddt_ the value comes as "11/1/2012 12:00:00 AM" , than dt_1 has the value #11/1/2012# and expenddt has "11/1/2012" so in textbox txtenddt the value appears as expenddt .

Now when i try to add a day to dt_1 as

Dim test As Date = dt_1.AddDays(+1)

Than the value in test comes as 11/2/2012, ie a month gets added and not the day. How can i add a day?can anyone help me with this issue?

here is a simple example:

Dim today As System.DateTime
Dim answer As System.DateTime

today = System.DateTime.Now
answer = today.AddDays(36)

SOURCE


截图

Well, tahnk you guys . i parsed The date to mm//dd/yyyy format and than added a day to it. When i posted this question i was unable to parse the date to mm/dd/yyyy format. Now i did it and this question is solved.

I think your output format is MM/DD/YYYY, so you can try dt_1.ToString("dd/MM/yyyy") to see the content in the format you expected.

You can also check the Day property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM