Date Subtraction

Hi, I have 2 dates. I would like to check if the both dates have 6 months difference(excluding days): e.g. 4/2/2018, 10/1/2018.

Is it possible to minus dates with dates?

@sangasangasanga Subtract new date minus old date and get number of days between them and compare with total number days for 6 months(180 odd days).

1 Like

Hi sanga

It is possible to minus dates

here is my example

But I found that UiPath can’t correctly read dd/MM/yyyy (02/04/2018) format so I recommend you to change the date format to another one like yyyy/MM/dd (2018/04/02).

Hi @sangasangasanga,

Try this:

( Convert.ToDateTime(“10/1/2018”).Date - Convert.ToDateTime(“04/02/2018”).Date).Days.ToString

This shall give you 182 as your output. If you need this in months, divide it by 30.

1 Like

@Shin_Sam @sangasangasanga

If the date format is an issue, a better way to do this would be to use DateTime.ParseExact() method and specify the exact format of the date:

(DateTime.ParseExact(“10/01/2018”,“MM/dd/yyyy”,CultureInfo.InvariantCulture)-DateTime.ParseExact(“04/02/2018”,“MM/dd/yyyy”,CultureInfo.InvariantCulture)).Days

This shall give you the same output (182) which as mentioned earlier you can divide by 30 to see if the dates have a 6-month difference or not.

1 Like

Thank you so much siddharth :slight_smile:
I had the same date issue before and now I know how to solve it~!

1 Like

Hi @siddharth. one more question - date addition. How can I add days. E.g with today’s date 26/10/2018, I would like to add 7 days thus, it should give me 02/11/2018. Is this possible? Do let me know. Thank you

@sangasangasanga Below statement Gives date after 7 days from today.

Now.AddDays(7)

1 Like

thank you

1 Like