I have input date as
01/28/2024
From today date it is one month previous how to find this .how to find it in if condition
I have input date as
01/28/2024
From today date it is one month previous how to find this .how to find it in if condition
You can do this Now.AddMonths(-1).ToString("MM/dd/yyyy").Equals(YourDateString)
If it is date variable then
Now.AddMonths(-1).ToString("MM/dd/yyyy").Equals(YourDateString.ToString("MM/dd/yyyy"))
cheers
If((DateTime.ParseExact("01/28/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).AddMonths(1) = DateTime.Today), True, False)
Hi @sruthesanju
Try this
DateTime.ParseExact("01/28/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) = DateTime.Now.AddMonths(-1)
Regards,
Hi @sruthesanju
Try this:
If: DateTime.ParseExact("01/28/2024", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture) = DateTime.Today.AddMonths(-1)
Then:
Message Box: "Given date is one month earlier than today."
Else:
Message Box: "Given date is not one month earlier than today."
Hope it helps!!
I wouldn’t recommend comparing strings here, the .Equals
method also works on a DateTime object.
Hey @sruthesanju
inputDate = DateTime.ParseExact(inputDateString, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
previousMonth As DateTime = DateTime.Today.AddMonths(-1)
if condition:
inputDate.Year = previousMonth.Year AndAlso inputDate.Month = previousMonth.Month
Assign Activity* : Parse the input date string to a DateTime object.
Dim inputDateString As String = “01/28/2024”
Dim inputDate As DateTime = DateTime.ParseExact(inputDateString, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)
Assign Activity* : Calculate the date one month before today.
Dim oneMonthBeforeToday As DateTime = DateTime.Today.AddMonths(-1)
If Activity* : Use an If activity to compare the input date with the calculated date.
If (inputDate = oneMonthBeforeToday) Then
’ The input date is exactly one month before today. Place your logic here.
Else
’ The input date is not exactly one month before today. Place your alternate logic here.
End If
Note: In the If activity, compare inputDate
and oneMonthBeforeToday
. If they are equal, execute the logic for when the input date is exactly one month prior. If not, execute the alternative logic.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.