Hi Guys,
I have two variables (defined as datetime)
latest_month and invoice_month
I intend to compare these two in a if loop , one data set of them is:
latest_month: 08/01/2019 00:00:00
invoice_month: 10/01/2018 00:00:00
But the result seems not really got compared in a numerical sense.
My if condition looks like this:
latest_month < invoice_month
Anybody could kindly help me out to enlighten me abit:
Should I further convert them into a MMM yyyy format for an easy comparison
Why my existing logic not working?
Thanks!
sarathi125
(Parthasarathi)
October 31, 2019, 5:05am
2
@Victor_Victory ,
use DateTime.Compare(latest_month, invoice_month) , do not use < or > operators to compare datetime. If those are with datetime datatype then it will work otherwise it will be compared as string.
Ajju
(Ajjayya Hiremath)
October 31, 2019, 5:08am
3
hello @Victor_Victory
both latest_month and invoice_month is of type system.dateTime ?
if not please convert both variable to datetime like below.
Latest_Month_Datetime = cdate(latest_month)
invoice_month_Datetime = Cdate(invoice_month)
then you can continue with your logic.
regards
Ajay
Hi Ajay,
If i have placed these two assign actions prior comparing them, can I consider them as system.dateTime?
dateTime_latestMonth = Convert.ToDateTime(str_latestMonth)
dateTime_invoiceMonth = Convert.ToDateTime(str_invoiceMonth)
Thanks!
Ajju
(Ajjayya Hiremath)
October 31, 2019, 8:34am
5
hi @Victor_Victory yes it is perfectly alright.
are you still facing issue??
Thanks Ajay. Issue resolved.
Ajju
(Ajjayya Hiremath)
October 31, 2019, 9:19am
7