Date Change

Hi Team,

I am trying to compare two dates
08Apr88 with 07/04/1988

07/04/1988 - This date reading as month/date/year. I want in Date/Month/Year format.

2 Likes

@robotics Converting date

1 Like

Hi @Robotics
Try with this buddy
Datetime.ParseExact(“07/04/1988”,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

this will give 07/04/1988 as 04/07/1988

Cheers @Robotics

If i use the above line of code i am getting the solution but for another date it got the format as
8Apr88 if i use the above line of code getting error as

String was not recognized as a valid datetime
my code is in Assign
acOpenDate= Datetime.ParseExact(“07/04/1988”,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

acOpenDate declared as String

1 Like

may i know what two date values you want to compare between @Robotics
kindly mention their format as well pls
Cheers @Robotics

I am comparing 2 dates
Date1 : Hardcoded - 04/07/1990. I have converted this now it is 07/04/1990
Date2 : This date i am fetching from a mainframe application. Getting the date as it is Apr0888.(mm/dd/yyy). I want this date also to be changed as 08/04/88

While converting the Date2 i am getting the above said error (String was not recognized as a valid datetime)

1 Like

Fine
to convert the Date2 we need different one as the format is different
so for that we need to mention as
Datetime.ParseExact("Apr0888”,“MMMddyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

make sure that you are getting the value from mainframe in this format Apr0888, MMMddyy, buddy

Cheers @Robotics

were you able to convert now @Robotics
any issue still

Yes still the issue exists. A small change i am getting the date format as 8Apr88.
My code is
Datetime.ParseExact("acOpenDate”,“MMMddyy”,System.Glo…
Error is :
Source Assign
Message : String was not recognized as a valid date time
Exception Type : Format Exception

Variable acOpenDate declared as String
Any changes i need to do further ?

1 Like

No worries
If the date format is 8Apr88
then we need to mention as
Datetime.ParseExact("8Apr88”,“dMMMyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

Now its converting, but if i provide the hard coded date as

30/05/2019

Error:
The datetime represented by the string is not supported in calender System.GlegorianCalendar

My code is
Datetime.ParseExact("30/05/2019”,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

1 Like

buddy @Robotics
there is no month of 30, thats why
we have to mention the hard corded date as
05/30/2019 to match the format mention here

Cheers

kindly try this and let know @Robotics
you were almost done
Cheers

Ok Palani the above error gets solved. But still the functionality is not good

EX :
Date1: 07/04/1987 < Date2: 08/04/88 : Output is Date1 is LESSER than Date2
Date1: 07/04/1987 < Date2: 08/04/88 : Output is Date1 is GREATER than Date2
Date1: 07/04/1988 < Date2: 08/04/88 : Output is Date1 is GREATER than Date2 - WHICH IS WRONG
Date1: 09/03/1988 < Date2: 08/04/88 : Output is Date1 is GREATER than Date2 - WHICH IS WRONG

It is working fine for year, but when it comes to date and month its getting failed. Need your help:-(

I have done some changes now date and year are fine. Only month is not working correctly.

Date1: 09/03/1988 < Date2: 08/04/88 : Current Output is Date1 is GREATER than Date2 - WHICH IS WRONG

1 Like

May i know the logic been used in if condition along with statement used in output @Robotics

Current code itself is working fine now. Thanks Palani.

1 Like

great
cheers @Robotics
kindly close this topic buddy that would help others