Solved

DateTime Assign: Cannot convert string to date time

  • 1 March 2023
  • 5 replies
  • 156 views

Badge +1

I have CSV file where I have a date/time field as “(1/30/2023 1:35:45 PM)”. What I want to do is figure out the Month and Year.

 

I am using the DateTime: Assign to convert the string into a datetime value. However, the only output I get from the bot is an unhelpful error “An exception occurred while parsing the date time”

 

No matter what string we enter, we get the same error. I’m not sure what we’re doing wrong. How have you made this work?

icon

Best answer by Diksha.M1 1 March 2023, 09:41

View original

5 replies

Userlevel 7
Badge +13

Hi @Alessandro 3854 ,

 

First please check what is the Date format you are getting on the System variable called Date. First assign it to a variable and display it after converting to String. You should follow the same format while assigning the Date from the CSV file and later you can choose you desired format while converting it to string.

Badge +2

Hi Alessandro 3854 ,

 

If you have the Date Time value in string format and while using DateTime: Assign to convert the string into a datetime value, Use the Custom Formats as M/d/y h:m:s a , It will give you the datetime D1 in correct format. 


Then you can use DateTime: To String action and use the variable D1 and the custom format as y or M to get the year and month respectively.

Thanks,

Diksha

Badge +1

Thanks for the help. Unfortunately I could not get it to work. I tried the following using your feedback.

=========

Example #1:
Date Time: 1/30/2023 1:35:45 PM
Custom Format: M/d/y h:m:s a

 

Example #2
Date Time: 1/30/2023
Custom Format: M/d/y

Example #3
Date Time: 1/30/2023
Custom Format: MM/dd/yyyy

 

Badge +2

Hi Alessandro 3854

Can you share more details about the issue.

I am using similar things and its working for me fine.

 

Thanks,

Diksha

Badge +1

This is odd. Tried it again and it worked. No change from my side.

I believe the steps outlined were correct, so I will assume this was an issue with the environment.

Reply