Question

Date Convertion

  • 2 January 2023
  • 5 replies
  • 46 views

Badge +7

Hello Everyone,

I want to convert any given date format to d/m/yyyy.

the input value may be Jan 1, 2023, 1 Jan 2023, 1-1-2023,,,, meaning the format is not fixed.

So I want to convert the given date to fixed format ex d/m/yyyy so we can work with the date further.

 

Any Idea how to do it?


5 replies

Userlevel 3
Badge +7

Hi @Mohamed Timor ,

 

Use the To string action to convert a datetime value to a string value. This action enables you to select a predefined format or specify a custom format for the output value.

Reference  link 

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-date-time-formats.html

 

Badge +7

Hi @Mohamed Timor ,

 

Use the To string action to convert a datetime value to a string value. This action enables you to select a predefined format or specify a custom format for the output value.

Reference  link 

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-date-time-formats.html

 

Hi @Tamil Arasu10 

This means I will defin a fixed format in the to string action. my question is there a way to do the convert for any given format. As the given format every time changes.

Userlevel 3
Badge +7

Hi @Mohamed Timor ,

Apologies, I missed seeing that any date format.

You can achieve the 2 ways :

  1. Use the excel advanced package with an set cell formula =TEXT(C5,"mm/dd/yyyy") to get the cell value. (each time, you can pass the date value to specific cell and set formula to get the values.)
  2. Use python scripts to convert the any date format to specific format. For this case, you need to include the all the date format scenarios into the scripts. like below 

import datetime

def format_date(field_value):
  try:
    #14/01/21---> 14/01/2021
    formated_date=datetime.datetime.strptime(field_value, '%d%m%y').strftime('%d-%m-%Y')
    return(formated_date)
  except ValueError:

 

Thanks!

 

 

 

Badge +7

Hi @Mohamed Timor ,

Apologies, I missed seeing that any date format.

You can achieve the 2 ways :

  1. Use the excel advanced package with an set cell formula =TEXT(C5,"mm/dd/yyyy") to get the cell value. (each time, you can pass the date value to specific cell and set formula to get the values.)
  2. Use python scripts to convert the any date format to specific format. For this case, you need to include the all the date format scenarios into the scripts. like below 

import datetime

def format_date(field_value):
  try:
    #14/01/21---> 14/01/2021
    formated_date=datetime.datetime.strptime(field_value, '%d%m%y').strftime('%d-%m-%Y')
    return(formated_date)
  except ValueError:

 

Thanks!

 

 

 

Hello @Tamil Arasu10 

 

Thanks for your reply, I tried the excel it works but not it does not accept all formats ex. jan 1 2023

but python works using pandas to_datetime function tested it and it works fine.

thanks again for help

Userlevel 3
Badge +7

Thanks for the heads-up.

Reply