maddy99
(mani)
April 18, 2022, 11:05am
1
Hi,
I am trying to get the string as Datetime format from an excel row.
But, bot is taking first one as month and second one as Date. Due to that bot is throwing error as “string is not recognized as a valid datetime”.
Datetime_variable = DateTime.ParseExact(Datetime123,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Datetime123 Value is : 18/4/2022 2:35:13 AM . From here I only need Date, could someone help me on this.
2 Likes
Convert.todatetime(Var).Date
Or if you just need it as a string then use var.Split(" "c).First
jack.chan
(Jack Chan)
April 18, 2022, 11:18am
4
to convert to datetime
dateTimevar = DateTime.ParseExact(dateTime123,"d/M/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture)
get date
dateTimevar.tostring(“dd/MM/yyyy”)
lakshman
(Ganta lakshman)
April 18, 2022, 11:18am
5
@maddy99
Welcome back to our UiPath community.
Try below expression.
DateTime.ParseExact(Datetime123,{“dd/MM/yyyy hh:mm:ss tt”,"dd/M/yyyy hh:mm:ss tt"},System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")
Hi
Welcome back to UiPath forum
If this is the date format in ur file
Then the below expression would help you resolve this issue
Datetime.ParseExact(Datetime123.ToString.SubString(0,10).Trim, {“dd/M/yyyy”, “dd/MM/yyyy”}, System.Globalization.CultureInfo.InvariantCulture)
For more details on Datetime refer this thread
Hi All,
My recent post on datatable [All About Datatable- UiPath] (All about Datatable - UiPath ) was received well in forum with great feedbacks and many suggested to provide some tutorial on topics which are discussed often in our forum
In regards to that I would like to share the commonly used expression for DATETIME conversion
Let’s get started one by one
1. Get Current Date in string format
Datetime.Now.ToString()
(Output - string type - “dd/MM/yyyy hh:mm:ss”)
**To get only current da…
Cheers @maddy99
maddy99
(mani)
April 18, 2022, 12:50pm
7
lakshman:
DateTime.ParseExact(Datetime123,{“dd/MM/yyyy hh:mm:ss tt”,"dd/M/yyyy hh:mm:ss tt"},System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")
Hi @Palaniyappan ,
Which variable type should be assigned to the above code, as I used DateTime variable and also string but getting this error.
jack.chan
(Jack Chan)
April 18, 2022, 1:03pm
9
@maddy99
try this instead
Datetime.ParseExact(Datetime123.SubString(0,10).Trim, "d/M/yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")
this code can be assigned to string
1 Like
Fine
If you want Datetime as a output variable then mention like this in assign activity
datetimevar = Datetime.ParseExact(Datetime123.ToString.SubString(0,10).Trim, {“dd/M/yyyy”, “dd/MM/yyyy”}, System.Globalization.CultureInfo.InvariantCulture)
Where datetimevar is a variable of type System.Datetime
Or
If you want as a string output
stroutput = Datetime.ParseExact(Datetime123.ToString.SubString(0,10).Trim, {“dd/M/yyyy”, “dd/MM/yyyy”}, System.Globalization.CultureInfo.InvariantCulture).ToString
Cheers @maddy99
1 Like
system
(system)
Closed
April 21, 2022, 1:08pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.