Formating in to date time

str_ATADate = 09/May/2023
str_ATSDate = 08/Apr/2023

Want date difference 09/May/2023-08/Apr/2023= 31days

I have converted

Date_ATADate=DateTime.ParseExact(str_ATADate,“dd/MMM/yyyy”,System.Globalization.CultureInfo.InstalledUICulture)

And Date_ATSDate= Convert.ToDateTime(str_ATSDate).Date.ToString(“dd/MMM/yyyy”) while converting taking date_ATSDate = 01/Jan/0001 but want date_ATSDate= 08/Apr/2023

Tried both method

Date diff = DateDiff(DateInterval.Day,convert.ToDateTime(date_ATSDate),convert.ToDateTime(date_ATADate))
=738647 days which is wrong

Required answer is 31days

Some one help me on this.

Hi @satish.rathi59,

DateDiff(DateInterval.Day,Cdate(“08/April/2023”),Cdate(“09/May/2023”))

This gives 31. If you don’t want to consider the existing dates then subtract 2.

In your equation it should be:

DateTime.ParseExact(str_ATADate,“dd/MMM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

Try this.

Hope it helps.

1 Like

@satish.rathi59

Please use this

System.Globalization.CultureInfo.InvariantCulture

Cheers

1 Like

ATA Date is perfect want ATS Date accurate I am not getting using above

Thanks for you comment but not found solution

Use InvariantCulture instead of InstalledUICulture.

If you are input date format is same as you mentioned, then you can just use CDate, need not use ParseExact.

1 Like

I have tried the same but thrown exception

Try this directly, No need of ParseExact.

DateDiff(DateInterval.Day,Cdate(str_ATSDate),Cdate(str_ATADate ))

1 Like

Hi @satish.rathi59 ,

Check this below codes,

firstDate(DateTime as type) = System.DateTime.ParseExact("08/Apr/2023","dd/MMM/yyyy",System.Globalization.CultureInfo.InvariantCulture)

endDate(DateTime as type) = System.DateTime.ParseExact("09/May/2023","dd/MMM/yyyy",System.Globalization.CultureInfo.InvariantCulture)

totalDays(Int32 as type) = (endDate-firstDate).TotalDays

Screenshot:

Hope this might help you :slight_smile:

3 Likes

@satish.rathi59

This is what I wanted you to try

DateDiff(DateInterval.Day,DateTime.ParseExact("24/Mar/2023","dd/MMM/yyyy",System.Globalization.CultureInfo.InVariantCulture),DateTime.ParseExact("03/Mar/2023","dd/MMM/yyyy",System.Globalization.CultureInfo.InVariantCulture))

image

cheers

1 Like

Hi @satish.rathi59

Try this code

string str_ATADate = “09/May/2023”;
string str_ATSDate = “08/Apr/2023”;

DateTime date_ATADate = DateTime.ParseExact(str_ATADate, “dd/MMM/yyyy”, System.Globalization.CultureInfo.InvariantCulture);
DateTime date_ATSDate = DateTime.ParseExact(str_ATSDate, “dd/MMM/yyyy”, System.Globalization.CultureInfo.InvariantCulture);

TimeSpan dateDiff = date_ATADate - date_ATSDate;
int daysDiff = dateDiff.Days;

Console.WriteLine(daysDiff);

1 Like

In StudioX, you can try this Modify date option out of the box as well.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.