cannot convert a prmitive value to the expected type 'Edm.DateTime'

Jayashri Thorat 351 Reputation points
2021-09-23T10:57:46.207+00:00

Hello All,

I am creating custom list form using js and HTML.

I am getting error mentioned in the title as : cannot convert a prmitive value to the expected type 'Edm.DateTime'

Below is the code, for checking on date thing:

**vDate and tillDate are variable declared for 2 dates existing column in list.
var todayDate = new Date();
var currentDate = todayDate.getFullYear()+ '-' + ((todayDate.getMonth() > 8) ? (todayDate.getMonth() + 1) : ('0' + (todayDate.getMonth() + 1)))+ '-' + ((todayDate.getDate() > 9) ? todayDate.getDate() : ('0' + todayDate.getDate()));

if( vDate >= currentDate)
{
if( tillDate >= currentDate)
{
var date = new Date(vDate);
date.setDate(date.getDate() + 7);
var third_date = moment(date).format('YYYY-MM-DD');
var fourth_date = third_date.toString();
if (tillDate <= fourth_date && tillDate >= vDate) {
{
saveAction();
location.reload();
}
else{
}
}**

Please assist.

Thanking in advance

Regards,
Jayashri

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,682 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jayashri Thorat 351 Reputation points
    2021-10-06T06:07:56.987+00:00

    Sorry for replying late.

    This problem/error occurred as a result of a blank value in the Date column.
    As a result, the problem was solved by inserting "Null" if the Date column value was blank.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-09-24T02:21:12.827+00:00

    Hi @Jayashri Thorat

    In sharepoint, the datetime column are in ISO8601 format (YYYY-MM-DDTHH:MM:SSZ). You could format the column like this:

     moment(date).format('YYYY-MM-DDTHH:mmZ')  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.