Subtract a date
Subtract a Month:
Subtract a Year:
But this method doesn't work correctly... if I calculate a 6 month period I get a wrong date.
Can you help me with this?
Subtract a Month:
Subtract a Year:
But this method doesn't work correctly... if I calculate a 6 month period I get a wrong date.
Can you help me with this?
Hi Fábio Nobre,
Add
One button
to a Form to try this code.
Try this which adds years, type a negative number to subtract.>>>>
Public
Class Form1 'This highlighted line should be one line of code in your code window.>>>>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Msg, Number As String
Dim Months As Double Dim StartDate, SecondDate As DateStartDate = Now
Dim IntervalType As DateIntervalIntervalType = DateInterval.Year
SecondDate = StartDate
DoNumber = InputBox(
"Enter number of years to add please.", "Years to add.") Loop Until IsNumeric(Number) = TrueMonths =
Double.Parse(Number)Msg =
"New date: " & DateAdd(IntervalType, Months, SecondDate).ToStringMessageBox.Show(Msg)
End SubEnd
ClassUse this version for months.>>
Public
Class Form1
'This highlighted line should be one line of code in your code window.>>>>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Msg, Number As String
Dim Months As Double Dim StartDate, SecondDate As DateStartDate = Now
Dim IntervalType As DateIntervalIntervalType = DateInterval.Month
SecondDate = StartDate
DoNumber = InputBox(
"Enter number of months to add please.", "Months to add.") Loop Until IsNumeric(Number) = TrueMonths =
Double.Parse(Number)Msg =
"New date: " & DateAdd(IntervalType, Months, SecondDate).ToStringMessageBox.Show(Msg)
End SubEnd
ClassRegards,
S_DS
Hi,
Add
One button
to a Form to try this code.>>>>
You can also Add minus 6 months.>>>>
Public Class Form1 'This highlighted line should be one line of code in your code window.>>>> My.Application.ChangeCulture("en-US") 'Repesents Midnight on Christmas Day. aDate = aDate.AddMonths(-6) MessageBox.Show(aDate.ToLongDateString & End Regards, S_DS
I'm using this code:
Private Sub okdata_Click()
Dim dater As Integer
If optano.Value = True Then
datafim.Text = Now
datain.Text = (DateValue(Now) - 365) & " " & TimeValue(Now)
ElseIf optsemestre.Value = True Then
datafim.Text = Now
datain.Text = (DateValue(Now) - 180) & " " & TimeValue(Now)
ElseIf optmes.Value = True Then
datafim.Text = Now
datain.Text = (DateValue(Now) - 30) & " " & TimeValue(Now)
ElseIf optsemana.Value = True Then
datafim.Text = Now
datain.Text = (DateValue(Now) - 7) & " " & TimeValue(Now)
End If
End Sub
These options are Radio Buttons, the user sellect one of these to define the time range a time
Or select another one named: "optperiodo" to manual-define the time range.
This timerange is used to calculate the number of hours that one industrial machine works inside of this range...
Can you help me? :\