Hi
How to convert date of format 12-jun-2019 to 2019-06-12
DateTime.ParseExact(row.Item(“date”).ToString(),“dd-MMM-yyyy”,System.Globalization.DateTimeFormatInfo.InvariantInfo).ToString(“yyyy-MM-dd”)
I am not getting syntax error. In excel it is not going to correct format
Simply use row.Item(“date”).ToString(“yyyy-MM-dd”)
@KarthikBallary Syntax Error ? What is the Error?
Please try this it worked.
Datetime.Parseexact(InDate,“dd-MMM-yyyy”,system.globalization.cultureinfo.invariantculture).ToString(“yyyy/MM/dd”)
@KarthikBallary Try this,
outDate = Datetime.ParseExact(InDate,“dd-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Where outDate is type of DateTime
Write Line = outDate.ToString(“yyyy-MM-dd”)
Alternatively:
you can create variable outDate with the type of String and assign
outDate = Datetime.ParseExact(InDate,“dd-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)
Hope this helps
@Bhavik_Solanki your and mine solution are same. Please check the comments.
@shubham_sethi, Yes you are right but I think he is using wrong DataType which I would like to highlight. Hope this make sense.
Guys, Format is not getting changed while writing back to excel
Ok let me tell the scenario,
I am doing data scraping-obtained data table
using for each row
row("date)=Datetime.ParseExact(row.item("date),“dd-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“yyyy-MM-dd”)
after for ends
same dt is tracked to excel
@KarthikBallary, Which DataType are you using while building table. I am assuming that you are using Write Range activity to write back to excel, so you must be supplying DataTable to that activity. If you date column is type of String then it will export data as you expected. If you are using DateTime then format will change as you demonstrated in above post.
Yes I am using write range activity
What is DataType of your column?
how to check datatype of a column
Ya data type is of String
Just for testing purpose add Write Line Activity with value: dataTableName.Columns(“Date”).DataType.ToString
Where “Date” is your column name.
it is of String
@KarthikBallary Are you trying to Convert the Date Column in Datatable to another Format and Save the Format in that way ?