Copy dates

Hi Team,

I am copying a date from a Query sheet to csv sheet through normal variable however the date in the Query formate is YYYY-MM-DD but the BOT copy it in other format in the csv sheet so is there any way to copy it as it’s?

Before writing the value to the CSV sheet, use the .ToString method to convert the date to a string data type. & then you write range it will keep the same format.

you mean like this?
image

I tried and it didn’t work

When you are working with DateTimes, if you don’t specify the format after ToString, it will add the default format, usually MM/dd/yyyy.

Here is the documentation that might be of use: DateTime.ToString Method (System) | Microsoft Learn

But short answer, you should write contract_start_date.Tostring(“yyyy-MM-dd”). You can also store that format in a string variable and use the variable between brackets.

Try like this

dateAsString = contract_start_date.Tostring(“yyyy-MM-dd”)

When copying a date from one source, like a Query sheet with the format YYYY-MM-DD, to another destination, such as a CSV file, it’s essential to ensure that the date format remains consistent. In UiPath, you can use the DateTime.ParseExact function to control the date format during the copy operation.

Here’s how you can achieve this:

  1. Read the date from the Query sheet using Read Range or any relevant activity.
  2. Use the DateTime.ParseExact method to convert the date to the desired format before writing it to the CSV sheet.

// Assuming ‘dateFromQuery’ is the date read from the Query sheet in the format YYYY-MM-DD
string dateFromQuery = “2023-10-27”; // Replace this with your actual date variable

// Define the format of the date in the Query sheet
string queryDateFormat = “yyyy-MM-dd”;

// Define the format you want in the CSV file
string csvDateFormat = “MM/dd/yyyy”; // Adjust this to match the desired format

// Convert the date to the desired format
DateTime dateInQueryFormat = DateTime.ParseExact(dateFromQuery, queryDateFormat, System.Globalization.CultureInfo.InvariantCulture);
string dateInCsvFormat = dateInQueryFormat.ToString(csvDateFormat);

// Now, ‘dateInCsvFormat’ contains the date in the format you want

You can then write dateInCsvFormat to your CSV file. This ensures that the date format is preserved as you desire.

I did this already

image

can you share the workflow?

image


Try This

Hi @omar_ismail

Please try this

DateTime.ParseExact(Input,"yyyy-mm-dd",System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy-mm-dd")