Forum Discussion
mwilliams71
Nov 19, 2021Brass Contributor
convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery/JavaScript
I'm attempting to use oListItem.set_item to insert date data into SharePoint from a custom form. I keep receiving "Request failed.String was not recognized as a valid DateTime. Essentially the date c...
ganeshsanap
Nov 20, 2021MVP
mwilliams71 Try using:
var formattedDate = new Date("2021-09-21").toJSON();
OR
var tempDate = new Date("2021-09-21");
var formattedDate = [tempDate.getMonth() + 1, tempDate.getDate(), tempDate.getFullYear()].join('/');
Use formattedDate variable to set the date column using oListItem.set_item().
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- mwilliams71Nov 20, 2021Brass ContributorI have 4 date fields, 2 that will be filled with a Date and 2 that will remain empty until later. I'm having a problem with 2 Date fields being empty at the time of submission. I get an error for the empty fields.
- ganeshsanapNov 22, 2021MVP
mwilliams71 Are those two date fields "Required" in column settings/list settings? If yes, you have to make them optional from list settings.
For empty date fields, you don't have to write ".set_item()" in your code.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- mwilliams71Nov 22, 2021Brass ContributorThanks for the reply ganesshsanap. No. they are not required. However, a month later when the Status of the form change to approved, I will need to allow the user to go to the form and submit those dates.
-Mike