Issue Comparing 2 DateTime Fields

Good Afternoon,
I am having an issue with a function that should compare different DateTime fields on a button press and then perform actions dependant on results.
Below is a copy of the code: -

// Function to Save ReSchedule
function saveReschedule () {
	var changed = false;
	var startDate = fd.field('Start_x0020_Date_x0020__x002f__x').value;
	var previousStartDate = fd.field('Previous_x0020_Start_x0020_Date_').value;
	if (startDate != previousStartDate) {
		fd.field('Time_x002f_Date_x0020_Changed').value = true;
		changed = true;
	var endDate = fd.field('End_x0020_Date_x0020__x002f__x00').value;
	var previousEndDate = fd.field('Previous_x0020_End_x0020_Date_x0').value;
	if (endDate != previousEndDate) {
		fd.field('Time_x002f_Date_x0020_Changed').value = true;
		changed = true;
	var allocatedTo = fd.field('Assigned_x0020_To').value.EntityData.Email;
	var previouslyAllocatedTo = fd.field('Previously_x0020_Allocated_x0020').value.EntityData.Email;
	if (allocatedTo != previouslyAllocatedTo) {
		fd.field('Allocation_x0020_Changed').value = true;
		changed = true;
	if (changed == true) {
		savedSchedule = true;;
	} else {
		fd.toolbar.buttons[0].style = "display: inline;";
		fd.container('Tab1').tabs[1].disabled = false;
		fd.field('Start_x0020_Date_x0020__x002f__x').disabled = true;
		fd.field('End_x0020_Date_x0020__x002f__x00').disabled = true;
		fd.field('Assigned_x0020_To').disabled = true;
		fd.field('Send_x0020_Allocation_x0020_Emai').value = false;
		fd.field('Notify_x0020_Account_x0020_Manag').value = false;

On first load of an Edit form the fields "Start Date" and "Previous Start Date" will always be identical as there is a function in fd.spSaved that takes the value of the "Start Date" field and pushes that into the "Previous Start Date Field". However when this function runs even if the fields have not been changed the test returns "TRUE".
Please see attached image

If I change both fields manually to the same date/time the test returns "TRUE" again but yet the date and time is identical??


Good Afternoon,

To compare different dates using the ==, !=, ===, and !== operators you need to use date.getTime()

In your case for example

If (startDate.getTime() != previousStartDate.getTime()) {
fd.field('Time_x002f_Date_x0020_Changed').value = true;
		changed = true;