Skip to main content
Solved

DateTime Assign: Cannot convert string to date time

  • February 28, 2023
  • 7 replies
  • 5554 views

Forum|alt.badge.img+2

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?

Best answer by Diksha.M1

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

View original
Did this topic help answer your question?

7 replies

Padmakumar
Forum|alt.badge.img+13
  • Navigator | Tier 3
  • 785 replies
  • March 1, 2023

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.


Diksha.M1
Forum|alt.badge.img+4
  • Navigator | Tier 3
  • 10 replies
  • Answer
  • March 1, 2023

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


Forum|alt.badge.img+2

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

 


Diksha.M1
Forum|alt.badge.img+4
  • Navigator | Tier 3
  • 10 replies
  • March 1, 2023

Hi Alessandro 3854

Can you share more details about the issue.

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

 

Thanks,

Diksha


Forum|alt.badge.img+2

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.


Forum|alt.badge.img+1
  • Cadet | Tier 2
  • 1 reply
  • March 11, 2024

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

How to do this Conversion...i tried with above steps mentioned but the error remains the same 
dateTime' expecting 'ZonedDateTime' received 'String'


Forum|alt.badge.img+2

Hi @Prade 1645 ,

My solution was
1. Remove the first “(“ and last “)”. I used a replace function
2. Then use the DateTime:Assign

  • Custom format
  • M/d/yyyy h:mm:ss a

Good luck!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings