代表者の戯言

How to plus/minus the date?



I often find myself doing this as well, so I'd like to share a memo on a program that adds or subtracts days from a date.



datetime

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


'tx1 is today's date

Dim dt As DateTime = DateTime.Now

Dim stdt As String


dt = dt.ToString

stdt = dt.ToShortDateString()

TextBox1.Text = stdt


End Sub



Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


'tx1(:today's date) Subtract tx2=tx3

Dim dt As DateTime

dt = TextBox1.Text


Dim tx2 As DateTime

tx2 = TextBox2.Text


Dim span As TimeSpan

span = tx2.Subtract(dt)


Dim tx3 As String

tx3 = span.Days

TextBox3.Text = tx3


End Sub


Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


'tx1(:today's date )plus tx4=tx5

Dim dt As DateTime

dt = TextBox1.Text


Dim tx4 As Integer

tx4 = TextBox4.Text


Dim plus As DateTime

plus = dt.AddDays(tx4)


TextBox5.Text = plus.ToShortDateString()


End Sub