# Manipulating DateTime

**URL:** <https://forum.uipath.com/t/manipulating-datetime/99118>\
**Category:** Help\
**Tags:** system, activities\
**Created:** [2. März 2019 um 10:27 UTC](https://forum.uipath.com/t/manipulating-datetime/99118 "2019-03-02T10:27:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon5199880](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@anon5199880](https://forum.uipath.com/u/anon5199880)\
**Post date:** [2. März 2019 um 10:27 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/1 "2019-03-02T10:27:03Z")

</div>

Hi,  
My current problem at the moment is that I want to get the current date and specify which month that date is in based on a condition. The condition is that +5 days from the start of a month, the bot will consider it the previous month. For example if the current date is between 1st of March and 5th of March inclusive, it will display the message “February 2019”.

Please help thanks.

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [2. März 2019 um 10:43 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/2 "2019-03-02T10:43:18Z")

</div>

HI @anon5199880

I have worked on a solution for you… it’s quite simple. Checkout the attached workflow

[DateCheck.xaml](https://global.discourse-cdn.com/uipath/original/3X/c/b/cbe749f66ad2c6422a924ddad0174d6a7ccaeef2.xaml) (6.6 KB)

Let me know whether this suits your requirement… If it solves the problem, please mark the answer as the solution so that it will help others who are looking for similar solutions 🙂

---

<div class="post-metadata">

**Author:** ![Djh](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/djh/32/50660_2.png) [@Djh](https://forum.uipath.com/u/Djh)\
**Post date:** [2. März 2019 um 10:43 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/3 "2019-03-02T10:43:34Z")

</div>

Use the condition Date.day \< 6 in an if statement, where date is the variable with the date you have started with

---

<div class="post-metadata">

**Author:** ![anon5199880](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@anon5199880](https://forum.uipath.com/u/anon5199880)\
**Post date:** [2. März 2019 um 12:39 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/4 "2019-03-02T12:39:47Z")

</div>

Hi @Lahiru.Fernando,  
Thanks a lot this almost solved all of my issues, but after going through the workflow I am concerned about if the date was 01/01/2019 for example. As the message box will display CurrentDate.Year.ToString, wouldn’t the output become something like December 2019?

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [2. März 2019 um 12:55 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/5 "2019-03-02T12:55:19Z")

</div>

Oh… yeah… in my solution it will display as December 2019… My bad i didnt handle that in the code. ☹

But you can easily check that using another IF condition… same as we check the day.  
In your sample date…  
If date’s month is January & day is \<= 5  
Then CurrentDateVariable.Year.AddYear(-1)  
Else  
You xan display the same current year…

Its very much similar to the existing if condition

---

<div class="post-metadata">

**Author:** ![anon5199880](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@anon5199880](https://forum.uipath.com/u/anon5199880)\
**Post date:** [2. März 2019 um 13:19 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/6 "2019-03-02T13:19:25Z")

</div>

Say if I wanted just the last two digits of the year, would this be the correct statement?  
CurrentYear = CurrentDate.AddYears(-1).ToString(“yy”)

EDIT: Never mind fixed the issue

---

<div class="post-metadata">

**Author:** ![anon5199880](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@anon5199880](https://forum.uipath.com/u/anon5199880)\
**Post date:** [2. März 2019 um 13:25 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/7 "2019-03-02T13:25:01Z")

</div>

Thanks, I believe this will solve the issues now

 ![image](https://global.discourse-cdn.com/uipath/original/3X/6/9/69f0fc5eec8e8f83132b5a18d2b1c0449eef0ebe.png)  
Is it correct if I put the condition equal to “01” for January?

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [2. März 2019 um 14:25 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/8 "2019-03-02T14:25:11Z")

</div>

Yes… that looks good.

And yeah… you can try “1” as well… just try a debug and make sure whether it captures 1 or 01 for the month…

---

<div class="post-metadata">

**Author:** ![anon5199880](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@anon5199880](https://forum.uipath.com/u/anon5199880)\
**Post date:** [2. März 2019 um 14:35 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/9 "2019-03-02T14:35:26Z")

</div>

Thanks for the advice, it wasn’t reading “01” as January so “1” is the correct one for the IF statement.

---

<div class="post-metadata">

**Author:** ![andrzej.kniola](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/andrzej.kniola/32/8835_2.png) [@andrzej.kniola](https://forum.uipath.com/u/andrzej.kniola)\
**Post date:** [2. März 2019 um 23:54 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/10 "2019-03-02T23:54:00Z")

</div>

You could simplify the whole logic by using a DateTime object as your effective date  
`DateTime effectiveDate = DateTime.Today.AddDays(-5)`  
And use that whenever you need to check `.Month` or `.Year` etc.  
This has an added benefit of being able to test corner cases (you can mock it easily) like year changes etc. and its consistent.  
Storing day, month and year in separate variables is just inviting an error to happen.

---

<div class="post-metadata">

**Author:** ![anon5199880](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@anon5199880](https://forum.uipath.com/u/anon5199880)\
**Post date:** [3. März 2019 um 03:13 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/11 "2019-03-03T03:13:05Z")

</div>

My God, you are right. This simplifies the solution a lot 😂.  
 ![image](https://global.discourse-cdn.com/uipath/original/3X/2/a/2a3785c0c189c12dd25232c73e87ba77fc38c8e4.png)  
Message Box displays in that format for my usage.  
In this case, all I need is the year and month so if I just -5 days from the current date, I will get the correct effective date for my usages as the day is not that important.

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [3. März 2019 um 06:22 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/12 "2019-03-03T06:22:13Z")

</div>

Wow… thats very very simple… didnt know we could use yyMM at the same time… Thanks for sharing…

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [6. März 2019 um 06:22 UTC](https://forum.uipath.com/t/manipulating-datetime/99118/13 "2019-03-06T06:22:23Z")

</div>

Geschlossen, am 6. März 2019 um 06:22 UTC

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