vboddu
(vboddu)
August 28, 2020, 6:38am
1
Hi All, need help in converting a string to required format which can be a string or date format as well
I have “19-MAY-2020” as a string and I want to convert either to date or string type which is 2020-05-19 when I use the below expression it is giving below error
Assign: String was not recognized as a valid DateTime
Expression:
DateTime=Date.ParseExact(“19-MAY-2020”, “yyyy-mm-dd”,CultureInfo.InvariantCulture)
ReqOutput: 2020-05-19 (String or Date)
Hi, used
Str var=CDate( Date_).ToString(“yyyy-MM-dd”)
1 Like
Yoichi
(Yoichi)
August 28, 2020, 6:45am
3
Hi,
Can you try the following expression?
Date.ParseExact("19-MAY-2020", "dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture).toString("yyyy-MM-dd")
This returns string type
Regards,
2 Likes
vboddu
(vboddu)
August 28, 2020, 6:48am
4
Shubham_Akole:
(“yyyy-MM-dd”)
I used this CDate("19-MAY-2020”).ToString(“yyyy-MM-dd”) and it is working as expected what if the same output should be Date Format ?
Hi @vboddu
Can you please check this Post might Help you,
Hey @seldo
Reason is, your row(5).tostring might contain date as well.
To check it, you can log this in output pane and check exact output.
Try This
Datum = Date.ParseExact(row.item(5).ToString,“dd/MM/yyyy hh:mm”,System.globalization.CultureInfo.InvariantCulture)
Or
Datum = Date.ParseExact(row.item(5).ToString,“dd/MM/yyyy hh:mm:ss”,System.globalization.CultureInfo.InvariantCulture)
Thanks
Latika
1 Like
vboddu
(vboddu)
August 28, 2020, 6:57am
6
@Yoichi it worked for “19-MAY-2020” but not for “9-MAY-2020” what if I need date type?
1 Like
Yoichi
(Yoichi)
August 28, 2020, 7:01am
7
Hi,
The following returns DateTime type.
Date.ParseExact("19-MAY-2020", "dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture)
Regards,
vboddu
(vboddu)
August 28, 2020, 7:01am
8
Date.ParseExact(“19-MAY-2020”, “d-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture).toString(“yyyy-MM-dd”)
This worked
1 Like
system
(system)
Closed
August 31, 2020, 7:01am
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.