Convert date to a string

Hi there,

I need to use the following IF condition: If the document created date equals today, then move to the folder.
How can I make todays date as a string? What should I put here?
image

1 Like

hi @NathaliaFawcett

You can directly compare this with Now.
You should be able to get a comparison.
if you need 26-04-2024 00:00:00
you can use something like
Now.AddHours(-Now.Hour).AddMinutes(-Now.Minutes).AddSeconds(-Now.Seconds)

Please check the function names once before saving expression.

Thanks

Hi @NathaliaFawcett,

It depends on the date format of your “Created” variable.

Let’s say the date format is 4 digits year + 2 digits month + 2 digits day.

Example: 20240425

So, you have to convert the current date to the same date format to compare it properly.

In this case, you can use:

DateTime.Now.toString(yyyyMMdd)

Example 2:
25-04-2024
DateTime.Now.toString(dd-MM-yyyy)

Hope it helps!

Hi @NathaliaFawcett

Can you please share the date format in a document. I will help you with condition.

Regards

Hi Gustavo,

I am downloading things from a website and the created day should be like this

1 Like

I am downloading things from a website and the created day should be like this
image

Hi @NathaliaFawcett,

DateTime.Now.toString(M/d/yyyy h:mm tt)

In this case, I understood that:

  • Month is one or two digits. One digit: 1 to 9 (without 0). Two digits: 10 to 12
  • Day is one or two digits. One digit: 1 to 9 (without 0). Two digits: 10 to 31 (This part I could not confirm considering the example you shared. So, if you have one example with days from 1 to 9, please share it. Then, I will be able to see if the format is 01 or only 1, for example)
  • Year is always four digits
  • Hour is one or two digits. One digit: 1 to 9 (without 0). Two digits: 10 to 12
  • Minute is always two digits. 00 to 59 (This part I could not confirm considering the example you shared. So, if you have one example with minutes from 1 to 9, please share it. Then, I will be able to see if the format is 01 or only 1, for example)
  • AM/PM

If this solves your problem and you agree, kindly mark the post that helped you the most as solution to close this topic.

If you need extra help or have any questions, please let me know :slight_smile:

Thanks!

You can get the Date From the Folder Name

Directory.GetCreationTime(folderPath)

@NathaliaFawcett you can take your date format from config “yyyyMMdd”, you need to use below code which convert the string to date based of format.

if (Convert.ToDateTime(yourCreatedDateVariable).ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
{
//use move folder logic
Directory.Move(sourceDirName, destDirName)
}

Explanation:

  • We convert the string variable (yourCreatedDateVariable) to a DateTime object using Convert.ToDateTime.
  • Then, we convert both the converted date and DateTime.Now to the desired format (yyyyMMdd) using ToString for proper comparison.

Important:

  • Replace "yyyyMMdd" with the actual format of your “Created” date variable if it’s different (e.g., dd-MM-yyyy for day, month, year).
  • Consider implementing error handling in case the conversion fails or the format is unexpected.

Finding the “Created” Date Format:

  • Check the downloaded file properties or use debugging tools within UiPath StudioX to inspect the format of the “Created” date variable.

Additional Tips:

  • You can use the UiPath Explorer tool to inspect the downloaded file structure and identify how the “Created” date is retrieved.
  • If you’re unsure about the format, you can try different formats like yyyyMMdd and dd-MM-yyyy and test your code.